I've seen similar questions here but all of them contain outdated answers which don't work.
So here is my question: I have a media folder which contains images for a gallery. I'm looping through images in this folder to display them. All images have crops but I can't get their url from xml.
Your script looks like it should work - what does it render if you add the following snippet where your "//imgPath is always empty string here" comment is:
How to get image crop Url from media using Razor?
Hi guys,
I've seen similar questions here but all of them contain outdated answers which don't work.
So here is my question: I have a media folder which contains images for a gallery. I'm looping through images in this folder to display them. All images have crops but I can't get their url from xml.
Here is how I do it:
@using umbraco.cms.businesslogic.media;
@using uComponents.Core;
@using uComponents.Core.uQueryExtensions;
@{
var folderId = Convert.ToInt32(@Model.GetProperty("galleryFolder").Value);
}
@if (@folderId > 0) {
Media startMedia = new Media(@folderId);
foreach(Media m in startMedia.GetChildMedia()) {
string imgPath = m.GetImageCropperUrl("crops", "GalleryThumb");
//imgPath is always empty string here
if (string.IsNullOrEmpty(imgPath)) {
imgPath = @m.getProperty("umbracoFile").Value.ToString();
}
<a rel="example_group" href="@m.getProperty("umbracoFile").Value.ToString()" title="@m.getProperty("caption").Value.ToString()">
<img alt="" src="/umbraco/imagegen.ashx?image=@imgPath&width=180&height=120&crop=resize">
</a>
}
}
example media node contains this xml:
<crops date=\"2012-08-03T17:59:28\"><crop name=\"GalleryThumb\" x=\"121\" y=\"137\" x2=\"587\" y2=\"448\" url=\"/media/6176/img1_b_GalleryThumb.jpg\" /></crops>
How can I get the url? It should be easy, but I can't find it.
Thanks.
Hi Zakhar,
Your script looks like it should work - what does it render if you add the following snippet where your "//imgPath is always empty string here" comment is:
Hi Hendy, thank you for your hint,
was empty in my case, so i tried
And it works, my bad.
Thanks one more time.
I couldn't get GetImageCropperUrl to work.
I suggest you use the solution in this post - it's by far the neatest: http://our.umbraco.org/projects/backoffice-extensions/image-cropper/image-cropper/32728-Get-Crops-with-Razor-syntax
Or if you only have one crop in that property, use:
is working on a reply...