Umbraco 7 ImageCropper - new crops added to property editor are not available
Hi
We're using ImageCropper configured to replace the file upload on images in the Media section on Umbraco 7.1.4.
When we initially setup the ImageCropper property editor, the initial crops work fine. However, when we go back to the property editor and add more crops, they are not available until we re-save the image. The same is true if we change the crop dimensions on the property editor - we have to manually re-save each image for the new dimensions to appear.
We have 100s of images in Media and so manually going in and re-saving each image is not really an option. We have tried to programmatically re-save the images with
var ms = ApplicationContext.Current.Services.MediaService;
var mediaItems = ms.GetDescendants(rootMediaId);
foreach(var item in mediaItems)
{
ms.Save(item, 2, true);
affectedFiles++;
}
but this doesn't seem to do the trick. Only manually going in on each image seems to trigger the update.
I am planning on a package to do just this, I've even written the code to do the healing (here) but unfortunately I've just not had the time to put it all together recently (I will).
You could look at using the code linked above or as an alternative you can do a check in you Razor as shown here.
v0.1 of the package is pretty much ready! You can download a Umbraco package pre-release from here (the zip file) or if you use NuGet there is a MyGet feed here.
Once installed, you just save the data type and wait while it finds and heals everything using that datatype.
Yeah, it's pretty well tested in terms of fixing crops (been through 4 or 5 different testers) but for release we want to have a UI hence the 0.1 version. There is a little roadmap here
Thank you. Tried the code you were using. Works & implemented mostly as you stated. However we tied our calls to each time a image cropper datatype is saved instead of when each datatype is saved. There would be a difference in that we update the nodes for the specific datatype being saved. This would however still benefit from the global heal using a admin button you mentioned but hopefully it would also prevent the loss of synchronization. In addition I noticed the crop coordinate updates are shifted off the focal point the user had set, (the effective focal point around the custom crop & zoom). So we recoded the update for the custom coordinates in our code. There is also a fix you can add directly to the datatype prevalues controllers, (apparently as a joke you can select to edit a crop but it will never be able to save changes, you have to delete the crop and readd it). So perhaps the image cropper datatype was never designed to be edited at all, (that would explain a lot of issues).
My crop healer only executes when a data type that implements the Image Cropper property editor is saved, you see that here so I'm not sure I understand your first change?
I would be interested to see the code changes you mention, do you have a fork or the code anywhere?
OK, I installed it and now it saves OK ... and writes to the error log.
The error was being caused by a node not having an image uploaded. This was actually caused by a test property I had added to a document (thanks, I had forgotten to remove it!!). Once I removed it, saving the Image Cropper DocType worked fine and reported no errors.
To test, I added an image to the media library but didn't upload an image. This is the error that was reported:
INFO Our.Umbraco.CropHealer.CropHealer - [Thread 219] Unable to attempt heal Image Cropper media property, possibly a svg or other format (NodeId:2647 DocumentTypeAlias:Image, PropertyAlias:umbracoFile)
Umbraco 7 ImageCropper - new crops added to property editor are not available
Hi
We're using ImageCropper configured to replace the file upload on images in the Media section on Umbraco 7.1.4.
When we initially setup the ImageCropper property editor, the initial crops work fine. However, when we go back to the property editor and add more crops, they are not available until we re-save the image. The same is true if we change the crop dimensions on the property editor - we have to manually re-save each image for the new dimensions to appear.
We are using ImageCropper in our code like so:
We have 100s of images in Media and so manually going in and re-saving each image is not really an option. We have tried to programmatically re-save the images with
but this doesn't seem to do the trick. Only manually going in on each image seems to trigger the update.
Has anyone got any ideas on this one?
Many thanks
Sam
Hi Sam,
I am planning on a package to do just this, I've even written the code to do the healing (here) but unfortunately I've just not had the time to put it all together recently (I will).
You could look at using the code linked above or as an alternative you can do a check in you Razor as shown here.
Jeavon
Thanks Jeavon, this looks like just the thing we need.
Got the same problem ... and it's a real PITA!!
How was the healing code (first link) intended to be used? Can I plug it in so it fires on some Umbraco event?
Hi Gordon,
v0.1 of the package is pretty much ready! You can download a Umbraco package pre-release from here (the zip file) or if you use NuGet there is a MyGet feed here.
Once installed, you just save the data type and wait while it finds and heals everything using that datatype.
If you have any issues please let me know.
Jeavon
v0.1 ... yikes!!! Are you sure it's ready? ;-)
I'll back everything up and give it a try...
Yeah, it's pretty well tested in terms of fixing crops (been through 4 or 5 different testers) but for release we want to have a UI hence the 0.1 version. There is a little roadmap here
Installed package via zip file, edited and saved doctype and got
Received an error from the server
Failed to save data for data type id 2623
Object reference not set to an instance of an object.
EXCEPTION DETAILS:
System.NullReferenceException: Object reference not set to an instance of an object.STACKTRACE:
Interesting, what a strange place to throw!
Couple of questions:
Thanks,
Jeavon
1. I didn't change anything - I just clicked Save
2. nothing in the log file ... I should mention that I have uSync installed though...?
3. Sorry, at the moment, no
Can I see / have the code so that I can see if I can debug it?
Absolutely, it's all here
Also I just had a stab in the dark by checking for null input in DetectIsJson, there is a new build here
Unfortunately, it still generates an error:
Received an error from the server
Failed to save data for data type id 2623
Object reference not set to an instance of an object.
EXCEPTION DETAILS:
System.NullReferenceException: Object reference not set to an instance of an object.STACKTRACE:
I checked that all the image files were present and I emptied the trash.
Unfortunately, I don't have time to debug on this project at the moment ... I will try and squeeze it it somehow / some time!
I've added some exception handling around that Umbraco stuff. I would love you to try out build 28 from here and see if you get anything logged.
Hello Jeavon,
Thank you. Tried the code you were using. Works & implemented mostly as you stated. However we tied our calls to each time a image cropper datatype is saved instead of when each datatype is saved. There would be a difference in that we update the nodes for the specific datatype being saved. This would however still benefit from the global heal using a admin button you mentioned but hopefully it would also prevent the loss of synchronization. In addition I noticed the crop coordinate updates are shifted off the focal point the user had set, (the effective focal point around the custom crop & zoom). So we recoded the update for the custom coordinates in our code. There is also a fix you can add directly to the datatype prevalues controllers, (apparently as a joke you can select to edit a crop but it will never be able to save changes, you have to delete the crop and readd it). So perhaps the image cropper datatype was never designed to be edited at all, (that would explain a lot of issues).
Hello Sentient,
My crop healer only executes when a data type that implements the Image Cropper property editor is saved, you see that here so I'm not sure I understand your first change?
I would be interested to see the code changes you mention, do you have a fork or the code anywhere?
Jeavon
OK, I installed it and now it saves OK ... and writes to the error log.
The error was being caused by a node not having an image uploaded. This was actually caused by a test property I had added to a document (thanks, I had forgotten to remove it!!). Once I removed it, saving the Image Cropper DocType worked fine and reported no errors.
To test, I added an image to the media library but didn't upload an image. This is the error that was reported:
That's great! Is it doing the job of "healing" the other crops?
Any other logs from CropHealer in the log file?
I've updated the methods to skip unpopulated cropper properties in build 29 as they don't need healing but logged the skip action.
is working on a reply...