Using media profile from code to get image URL

Topics: General, Writing modules, Writing themes
Jan 21, 2015 at 10:32 PM
Hi All,

On a particular page I have a list of objects returned via a WebAPI which is then rendered on the page using AngularJS.

Within the ng-repeat I am doing an ng-src for an <img> tag which then displays the image.

I want to use a media profile (resizing) to set this image URL in the WebAPI call and because I'm using Angular I can't use a @Display.MediaUrl() call in the View file.

I've looked through the Orchard.MediaLibrary.Shapes code and found where the image is manipulated using the profile settings but can't see to get this called correctly from within the controller.

Is it possible to have this feature called from code and not from a view?

Thanks
Jan 26, 2015 at 5:03 AM
The solution is to use IImageProfileManager from Orchard.MediaProcessing.Services.
private readonly IImageProfileManager _imageProfileManager;

public YourClass(IImageProfileManager imageProfileManager) {
    _imageProfileManager = imageProfileManager;
}

public void GetProfie(string mediaUrl) {
    _imageProfileManager.GetImageProfileUrl(mediaUrl, "ProfileName");
}
And that's it!
Marked as answer by red32 on 1/25/2015 at 9:03 PM