Copied to clipboard

Flag this post as spam?

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


  • Damien (Slipoch) 62 posts 346 karma points
    Mar 17, 2017 @ 00:26
    Damien (Slipoch)
    0

    Change Crop Image to standard media

    Hi everyone, is there any way to change a picture uploaded by image cropper to a standard media Image?

    I cannot work out quite how to do it.

    I need to do this in a model or a controller, so C# please. Basically I need to 'copy' the base image without the cropping into the media picker field on a different ipublishedcontent object.

    Cheers for any help.

  • Damien (Slipoch) 62 posts 346 karma points
    Mar 21, 2017 @ 01:02
    Damien (Slipoch)
    100

    Ok, given I didn't have any replies or suggestions I am posting a workaround.

    This is messy and should only be used if there is no other option.

    Get the cropped image, then create a new media item using the image source.

    im is my image folder node.
    tp[] is an array of strings (file path split by '/') index 3 is the name of the file.

    var tempImg = tempNode.GetPropertyValue("headshot");
    var tp = ((Umbraco.Web.Models.ImageCropDataSet)tempImg).Src.Split('/');
    var img = medServ.CreateMedia(tp[3], im, "Image");
                            img.SetValue(Constants.Conventions.Media.File, ((Umbraco.Web.Models.ImageCropDataSet)tempImg).Src);
                            medServ.Save(img);
    
Please Sign in or register to post replies

Write your reply to:

Draft