Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Cassar 5 posts 81 karma points
    Mar 07, 2016 @ 22:41
    Mark Cassar
    0

    ImageCropDataSet GetCropUrl not returning src of image

    I am quite new to Umbraco and was trying out Umbraco 7.4 with the models builder https://github.com/zpqrtbnk/Zbu.ModelsBuilder.

    I have a document type 'Activity' which has got a cropped image field with alias 'featuredImage'.

    When I call the following Razor code, it produces the correct result:

    var activityImageUrl = featuredActivity.GetCropUrl("featuredImage", "Listing Image");
    //returns "/media/1013/bigstock-friends-having-party-on-a-boat-74125045.jpg?center=0.47666666666666668,0.4656319290465632&mode=crop&width=350&height=350&rnd=131018659910000000"
    

    while

    var activityImageUrl = featuredActivity.FeaturedImage.GetCropUrl("Listing Image");
    //featuredActivity.FeaturedImage is generated by the models builder and is equivalent to featuredActivity.GetPropertyValue<Umbraco.Web.Models.ImageCropDataSet>("featuredImage");
    //returns "?center=0.47666666666666668,0.4656319290465632&mode=crop&width=350&height=350"
    //As you can see, it does not include the 'src'
    

    If I check the value of featuredActivity.FeaturedImage.Src, it is correct, i.e. contains the value "/media/1013/bigstock-friends-having-party-on-a-boat-74125045.jpg". Thus should I use featuredActivity.FeaturedImage.Src + featuredActivity.FeaturedImage.GetCropUrl("Listing Image"), it will output the correct result but I think GetCropUrl should output the correct result immediately without having to concatenate the Src.

    Anything which I'm doing wrong?

    Thanks in advance for your help!

  • Mark 255 posts 612 karma points
    Mar 27, 2016 @ 19:49
    Mark
    0

    I had a similar issue.

    I had also assumed that the GetCropUrl method could be called on a content page, and passing in the property name of an image picker on that page as the first parameter would work.

    The confusion arises because a media property also returns IPublishedContent, and I suspect the GetCropUrl method is only expected to be used for media instances of IPublishedContent, e.g. Umbraco.TypedMedia(1010).GetCropUrl(...

    The first parameter you used ("featuredImage") is actually the media item property alias, which is usually "umbracoFile", in which case you should just use the GetCropUrl override that expects only the cropAlias. You only need the override with propertyAlias if you use a media property other than "umbracoFile".

    I suspect a lot of others will have this issue too!

  • Mark Cassar 5 posts 81 karma points
    Mar 28, 2016 @ 13:15
    Mark Cassar
    0

    I didn't understand you correctly. So what exactly are you stating, that you cannot use featuredActivity.FeaturedImage.GetGropUrl?

    The featuredActivity.FeaturedImage is equivalent to featuredActivity.GetPropertyValue<Umbraco.Web.Models.ImageCropDataSet>("featuredImage") in this case.

    It would help if you can explain to me more clearer so that I can understand the possible solution better.

  • Mark 255 posts 612 karma points
    Mar 29, 2016 @ 18:13
    Mark
    1

    Hi @Mark

    IPublishedContent is returned for both UmbracoHelper.TypedContent(int) and also UmbracoHelper.TypedMedia(int). The former returns a contentItem (a document from the Content section) and the latter returns a mediaItem (an item from the Media section).

    Looking at the GetCropUrl() methods in reflector / ILSpy it looks like they only work on IPublishedContent of type mediaItem.

    When you provide a propertyAlias parameter to GetCropUrl(), you are actually saying, "I'm not using the media item's umbracoFile as the value for the propertyAlias, I'm using a different value".

    The Umbraco documentation (link below) implies GetCropUrl() will work for IPublishedContent of type contentItem, but I think this is incorrect, hence your (and my) initial misunderstanding.

    https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/image-cropper

    If your featuredActivity object is a documentItem then I don't think what you're doing will work. But I may be completely wrong, as I haven't taken the time to test any of this, and I may have misunderstood your initial question, if so I'm wasting everyone's time...

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 29, 2016 @ 07:48
    Dan Diplo
    0

    I'm having the exact same issue. I would expect that:

    Model.Content.GetPropertyValue<ImageCropDataSet>("imagePropertyAlias").GetCropUrl("cropAlias")
    

    would work and return the full URL.

    But what it seems to return is the querystring crop parameters without the path to the image (ie. without the value of Src).

    What makes me think this is a bug is that it sometimes works, but then just stops working.

Please Sign in or register to post replies

Write your reply to:

Draft