@if (CurrentPage.HasValue("miniFigure"))
{
var cropAlias = string.Empty;
switch ((int)CurrentPage.miniFigure)
{
case 37:
cropAlias = "myCropAlias1";
break;
case 38:
cropAlias = "myCropAlias2";
break;
}
var myImageUrl = string.Empty;
if (!string.IsNullOrEmpty(cropAlias))
{
myImageUrl = CurrentPage.GetCropUrl("imageCrop", cropAlias);
}
else
{
myImageUrl = ImageCropperTemplateExtensions.GetCropUrl(CurrentPage, propertyAlias: "imageCrop");
}
<img src="@myImageUrl" />
}
In this snippet, the Radiobutton list property alias is "miniFigure" and the cropper property alias is "imageCrop" and my two crop aliases are "myCropAlias1" & "myCropAlias2".
Additionally I am using the prevalue ID from my radiobutton list to decide which one to use. If your option in the radiobutton list actually contained the crop alias itself you could simplify to something like this:
I've tested this through again and it seems to work perfectly for me, however the "Original" does get a url like this "http://umbraco7docs.local/media/1007/desert.jpg?center=0.38333333333333336,0.5325&mode=crop&rnd=130415998280000000" but because this doesn't have a width or height it is not resized and so shows the original image. But in your case you are seeing the first crop for original, right?
While the sample above seems to work well for me, I have altered it so that it does now get only the original path of the image when set as such, here is the code (please note the 2 @using statements):
v7.1 image cropper display cropped image based on radiobutton list selection
I've added the image cropper to a doctype, the image cropper has 2 cropping options.
I want the user to be able to select which cropped image is displayed, by the use of a radiobutton list.
The radiobutton list values are:
If the user selects "original image" the uploaded image is displayed, without being cropped.
If they select either of the other options, the corresponding cropped image will be displayed.
How can I achieve this using razor?
I don't know how to check which radiobutton has been checked, or how to display the "original" uploaded image.
Any help would be greatly appreciated.
Cheers, JV
Hi JV,
Great question, here is how I would do it:
In this snippet, the Radiobutton list property alias is "miniFigure" and the cropper property alias is "imageCrop" and my two crop aliases are "myCropAlias1" & "myCropAlias2".
Additionally I am using the prevalue ID from my radiobutton list to decide which one to use. If your option in the radiobutton list actually contained the crop alias itself you could simplify to something like this:
This would mean your radio button list options would have to be:
Jeavon
Hi Jeavon,
This is great, however the "original" image doesn't display in either option.
It just displays the first crop image, which in my case is the 680x200 image.
How can the original image display without the "?crop=..." following the .jpg extension?
Cheers, JV
Hi JV,
Could you post your code? It might just be because I have misspelled "original" in the check?
Jeavon
Hi Jeavon,
I noticed the misspelling and tried lowercase as well to no avail.
Here's the code I'm using:
Hi JV,
Ok, is it right that the HasVaue is on imageSize but the property of the cropper is "imageCrop"?
Could you try:
To see if you get the original image for all?
Jeavon
Hi Jeavon,
Ok I tried that, but it still displays the cropped image instead of the original.
The imageSize refers to the radiobutton list, imageCrop is the image cropper datatype alias on my doctype.
Cheers, JV
Ok, could you post me the full image URL?
I've tested this through again and it seems to work perfectly for me, however the "Original" does get a url like this
"http://umbraco7docs.local/media/1007/desert.jpg?center=0.38333333333333336,0.5325&mode=crop&rnd=130415998280000000"
but because this doesn't have a width or height it is not resized and so shows the original image. But in your case you are seeing the first crop for original, right?This is my code now:
Hi JV,
While the sample above seems to work well for me, I have altered it so that it does now get only the original path of the image when set as such, here is the code (please note the 2 @using statements):
Please substitute "umbracoFile" and "cropSelector" for your own property aliases.
Jeavon
Thanks Jeavon,
That works perfectly! Thank you for your patience and effort. I'm hoping this solution comes in handy for other users.
For those wishing to use this method, ensure that your radiobutton list value is the same as your image cropper alias.
e.g. To display my "680x200" cropped image, my selected radiobutton value was "680x200".
Cheers, JV
is working on a reply...