Using the ImageCropper datatype on Media - razor output?
Hi everyone
I hope someone will be able to help me :)
What I'm trying to do:
I have a Node with several Childnotes, and I want to loop through those and output a cropped image from each.
So I created a new datatype called "ImageCropper" with the "Image Cropper" property editor.
I then added it to the "Image" Media type with the alias "crop", added a crop named "gallerithumb" (80x40 px) and uploaded an image (with a crop, of course). The Media Picker I'm using on each childnode has the alias of "billede".
Now my code looks like this, but I'm getting an internal server on the URL that's beeing added:
@foreach(var slideItem in CurrentPage.Children){ var image = Umbraco.Media(slideItem.billede.ToString()); <*img src="@image.GetCropUrl("crop", "gallerithumb")" /> }
I only experienced this when I hadn't set up the media type correctly. Ensure that the Media Type for the Image is as the default except you just chand the data type (i.e. it's still called "umbracoFile")
Then ensure the alias of the crop is typed correctly.
Then sometimes. I just open the image and save it again..This seems to ensure the crops are saved.
Sometimes I got the huge almost zero crops as you did and so I just tried altering the zoom of the crop a little and that seemed to help.
Using the ImageCropper datatype on Media - razor output?
Hi everyone
I hope someone will be able to help me :)
What I'm trying to do:
I have a Node with several Childnotes, and I want to loop through those and output a cropped image from each.
So I created a new datatype called "ImageCropper" with the "Image Cropper" property editor.
I then added it to the "Image" Media type with the alias "crop", added a crop named "gallerithumb" (80x40 px) and uploaded an image (with a crop, of course). The Media Picker I'm using on each childnode has the alias of "billede".
Now my code looks like this, but I'm getting an internal server on the URL that's beeing added:
The URL output is: http://xyz.dk/media/1006/galleridemo.jpg?crop=0.0000000000000005329070518201,0.15708915145005381,-0.0000000000000010658141036402,0.14473684210526266&cropmode=percentage&width=80&height=40&rnd=130444646360000000
The error I'm getting: Index was outside the bounds of the array.
Does anyone have an idea? :)
Hi Signe and welcome to our :)
Have you had a peek at the documentation on the image cropper here http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors-v7/Image-Cropper ?
Perhaps that can give you some inspiration in order how to loop through the images.
Hope this helps.
/Jan
Hi Jan
Thank you for your reply! :)
I've read the documentation, but unfortunately couldn't get it to work. I tried using this, as described:
This gives me the following src: /media/1001/galleridemo.jpg?mode=pad&rnd=130444646360000000
So now the crop is completely ignored.
I'm super confused because I do think the docs make sense, but it's just not working with my site :)
To use the cropper I alter the property for the "Image" media type to use the Image Cropper instead of the "upload" property.
For the sub nodes I then just use a normal media picker and the following code in the parent content Item:
Hi Robert
That sounds exactly like what I'm trying to do :)
Unfortunately your snippet gives me the same result as the one in the docs: src: /media/1001/galleridemo.jpg?mode=pad&rnd=130444646360000000
(Crop being ignored)
Did you ever experience this?
BTW: I'm using Umbraco 7.1.2 if that helps
I only experienced this when I hadn't set up the media type correctly. Ensure that the Media Type for the Image is as the default except you just chand the data type (i.e. it's still called "umbracoFile")
Then ensure the alias of the crop is typed correctly.
Then sometimes. I just open the image and save it again..This seems to ensure the crops are saved.
Sometimes I got the huge almost zero crops as you did and so I just tried altering the zoom of the crop a little and that seemed to help.
I got it working, thank you guys! :)
Roberto, your method worked for me too (once I realized I had a typo in my code, meh), so this is the final result (inside the loop):
Great... Glad you got it working.
Please can you mark my post with a high five?
Rob
@Robert, #h5yr x 2
I'd love to Roberto, but I can't seem to do that yet.. Will get back to that though ;)
@Signe, you should be able to find a green tick on @Robert correct solution, click that
Ah got it, sorry :)
Marking correct solution is same as 20 h5's :-)
Great. Thanks for that! I'm loving the Umbraco community!!
is working on a reply...