Copied to clipboard

Flag this post as spam?

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


  • Bilal Haidar 144 posts 410 karma points
    Sep 21, 2016 @ 19:34
    Bilal Haidar
    0

    Using mediaHelper to return a thumbnail fails

    Hi, I am making use of:

    scope.thumbnail = mediaHelper.resolveFileFromEntity(ent, true);
    

    The above returns:

    <img alt="" src="/media/1001/dewgong_large.png?width=500&amp;mode=max&amp;animationprocessmode=first" ng-show="thumbnail" ng-src="/media/1001/dewgong_large.png?width=500&amp;mode=max&amp;animationprocessmode=first">
    

    How to return a thumbnail instead of a big picture?

    Is this the right way to go or I should be returning a certain "Crop Alias" Url from the server to use?

    Thanks /Bilal

  • Sven Geusens 169 posts 881 karma points c-trib
    Sep 22, 2016 @ 10:39
    Sven Geusens
    0

    I have no idea what that mediaHelper is you are using and can't seem to find any documentation on it.

    If you have the node that contains the image as an IPublishedContent (which you should for displaying that node)

    you can do the following to display the image as a cropped image

    @if (VarThatIsAnIPublishedContent.HasValue("ImagePropertyAlias"))
    {
    var imageToCrop = Umbraco.TypedMedia((int)VarThatIsAIPublishedContent.GetValue("ImagePropertyAlias"));
         <img src="@imageToCrop.GetCropUrl(270, 161)" alt="" /> //Specific crop
         <img src="@imageToCrop.GetCropUrl("name of predefined crop")" alt="" /> //Named crop
    }
    

    if you already have the Media item as an IPublishedContent you can forgo the first 2 commands and run the GetCropUrl directly on the media item.

  • Bilal Haidar 144 posts 410 karma points
    Sep 22, 2016 @ 11:48
    Bilal Haidar
    0

    Thanks for your help Sven.

    mediaHelper is a service under "Belle". More you can read here: https://umbraco.github.io/Belle/#/api/umbraco.services.mediaHelper

    The code you provided me suits more front-end views. In my case, I am developing a backoffice plugin, hence in my views and angularjs code, I don't have access to UmbracoHelper "Umbraco". Am I right?

    For now, all what i did is make use of the embedded ImageProcessor n Umbraco. When the user selects a Media Item from the media picker, I simply generate a thumbnail by appending "?width=100" on the image url itself.

    Let me know please if there is a better way of doing the same thing.

    /Bilal

Please Sign in or register to post replies

Write your reply to:

Draft