Copied to clipboard

Flag this post as spam?

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


  • Alejandro Ocampo 67 posts 330 karma points c-trib
    Jan 16, 2015 @ 12:21
    Alejandro Ocampo
    0

    How to get the source image from ImageCropper

    Hi there, 

    I'm using the imageCropper and I couldn't figure out how to get the source image, is there any to way to get it without using the json....

    e.g.

           var jsonObject = JObject.FromObject(media.GetValue("cropper"));
                    var src = jsonObject.Property("src").Value;

    I need to get the src using "IMedia" and "IPublishedContent" is it possible ?? ... any ideas ?

    Thanks,

    Ale.

  • Dan Lister 416 posts 1974 karma points c-trib
    Jan 16, 2015 @ 12:27
    Dan Lister
    3

    Hi Ale,

    The source image should be available from the media.Url property if your media variable is of type IPublishedContent.

    Hope that helps.

    Thanks, Dan.

  • Tobias Klika 101 posts 570 karma points c-trib
    Jan 16, 2015 @ 12:28
    Tobias Klika
    1

    UmbracoHelper.TypedMedia or UmbracoHelper.Media?
    I am not sure if I understand your question ;-)

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 16, 2015 @ 12:48
    Jeavon Leopold
    104

    For IMedia you will need to something like this (assuming "media" is IMedia)

    using Umbraco.Web.Models
    
    var imageCrops = JsonConvert.DeserializeObject<ImageCropDataSet>(media.GetValue("cropper"));
    var src = imageCropDataSet.Src
    
  • Alejandro Ocampo 67 posts 330 karma points c-trib
    Jan 16, 2015 @ 12:55
    Alejandro Ocampo
    0

    @Dan I'm using the cropper as a "Main" image in the media type .. so when you do media.url in a normal upload field it will read the "umbracoFile" property.

    in this situation, the cropper save a json with all the options... e.g.

    { "focalPoint": { "left": 0.23049645390070922, "top": 0.27215189873417722 }, "src": "/media/SampleImages/1063/pic01.jpg", "crops": [ { "alias": "banner", "width": 800, "height": 90 }, { "alias": "highrise", "width": 80, "height": 400 }, { "alias": "thumb", "width": 90, "height": 90 } ] }

    so media.url will throw an exeption.

    @Tobias I'm hooking in to ther saving event ... so at that point what I got is a list of IMedia.

    private void MediaService_Saved(IMediaService sender, SaveEventArgs<IMedia> e)

    I need to get the image src at this point using a IMedia and later I need to get the image src from an IPublishedContent becuase I'm creating a model for my "image" item.

    does that make sense ??

    Thanks for you awesome response time :)

    Ale.

     

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 16, 2015 @ 13:06
    Jeavon Leopold
    1

    Actually you use that same method with with IPublishedContent to get the original source of the image from any Cropper Json data.

  • Alejandro Ocampo 67 posts 330 karma points c-trib
    Jan 16, 2015 @ 13:10
    Alejandro Ocampo
    0

    @jeavon yes, seems like this is the only way to do it is using the json...

    from and IPublishedContent you can do "media.GetProperty("upload").DataValue;".

    Would be great to keep the src apart of the json, this could be useful sometimes.

    Thanks!

    Ale.

     

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 16, 2015 @ 13:14
    Jeavon Leopold
    1

    Yes it is the only way.

    For IPublishedContent I would probably not use the DataValue but get the property value as a string as there are a few additional checks in there but the result would be the same.

    e.g.

    media.GetPropertyValue<string>("upload")
    
  • Damian Chambers 23 posts 87 karma points
    Aug 17, 2017 @ 22:13
    Damian Chambers
    0

    Still looking for a solution for this problem.

Please Sign in or register to post replies

Write your reply to:

Draft