Copied to clipboard

Flag this post as spam?

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


  • Nathan Reece 62 posts 376 karma points
    Aug 27, 2020 @ 06:23
    Nathan Reece
    0

    Converting iMedia to image in Umbraco 8

    I have uploaded an image to Umbraco using code.

    This returns an IMedia object. Now that I have inserted the image into Umbraco I want to use the the CropUrl.

    Does anyone know how to convert an IMedia to Image?

  • David Armitage 510 posts 2082 karma points
    Aug 27, 2020 @ 06:33
    David Armitage
    100

    Hi Nathan,

    I am not sure you need to convert to an Image. I would say you want to be converting to IPublishedContent.

    You then have all the usual fields .Url, .GetCropUrl etc.

    I think this is what you need.

    IMedia media = "your insert code here"
    if(media != null)
    {
         IPublishedContent image = Umbraco.Media(media.Id);
         modelFromSession.CompanyLogoUrl = image.GetCropUrl("companyLogo");
    }
    

    Regards

    David

  • Nathan Reece 62 posts 376 karma points
    Aug 27, 2020 @ 06:35
    Nathan Reece
    0

    Thanks Dave,

    Ill try that out and let you know how I get on.

  • David Armitage 510 posts 2082 karma points
    Aug 27, 2020 @ 06:37
    David Armitage
    1

    No worries. I'm pretty sure that's what you need.

  • Nathan Reece 62 posts 376 karma points
    Aug 27, 2020 @ 06:43
    Nathan Reece
    0

    Cheers Dave,

    Problem Solved :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies