Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sam Flanagan 47 posts 147 karma points
    Oct 29, 2014 @ 23:57
    Sam Flanagan
    0

    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:

    IPublishedContent imageMedia = Umbraco.TypedMedia(CurrentPage.image);
            string imageUrl = "";
    
            if (imageMedia != null)
            {
                imageUrl = imageMedia.GetCropUrl("Letterbox").IfNullOrWhiteSpace(imageMedia.GetCropUrl(width: 666, height: 200));
            }
    
            if (imageUrl != "")
            {
                <img src="@imageUrl" alt="@imageMedia.Name" />
            } 
    

    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.

    Has anyone got any ideas on this one?

    Many thanks

    Sam

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 30, 2014 @ 00:08
    Jeavon Leopold
    100

    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

  • Sam Flanagan 47 posts 147 karma points
    Nov 02, 2014 @ 15:14
    Sam Flanagan
    0

    Thanks Jeavon, this looks like just the thing we need.

  • Gordon Saxby 1444 posts 1855 karma points
    Jan 14, 2015 @ 17:06
    Gordon Saxby
    0

    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?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 14, 2015 @ 17:26
    Jeavon Leopold
    0

    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

  • Gordon Saxby 1444 posts 1855 karma points
    Jan 14, 2015 @ 18:34
    Gordon Saxby
    0

    v0.1 ... yikes!!! Are you sure it's ready? ;-)

    I'll back everything up and give it a try...

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 14, 2015 @ 18:39
    Jeavon Leopold
    0

    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

  • Gordon Saxby 1444 posts 1855 karma points
    Jan 15, 2015 @ 12:33
    Gordon Saxby
    0

    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:
    at Our.Umbraco.CropHealer.CropHealer.DetectIsJson(String input)
       at Our.Umbraco.CropHealer.CropHealer.SerializeToCropDataSet(String json)
       at Our.Umbraco.CropHealer.CropHealer.HealContentItems(IEnumerable`1 content, IEnumerable`1 cropperContentProperties, List`1 dataTypeCrops, IDataTypeService dts, IContentService cs)
       at Our.Umbraco.CropHealer.CropHealer.SeekAndHeal(IDataTypeDefinition dataType, IDataTypeService dts)
       at Our.Umbraco.CropHealer.UmbracoEvents.DataTypeService_Saved(IDataTypeService sender, SaveEventArgs`1 e)
       at Umbraco.Core.Events.TypedEventHandler`2.Invoke(TSender sender, TEventArgs e)
       at Umbraco.Core.Services.DataTypeService.SaveDataTypeAndPreValues(IDataTypeDefinition dataTypeDefinition, IDictionary`2 values, Int32 userId)
       at Umbraco.Web.Editors.DataTypeController.PostSave(DataTypeSave dataType)
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 15, 2015 @ 12:41
    Jeavon Leopold
    0

    Interesting, what a strange place to throw!

    Couple of questions:

    1. What did you change on the data type, add a crop, edit a crop size etc...
    2. Are there any entries in /App_Data/Logs/UmbracoTraceLog.txt from the Crop Healer?
    3. Is there any chance I could get a copy/backup of your database?

    Thanks,

    Jeavon

  • Gordon Saxby 1444 posts 1855 karma points
    Jan 15, 2015 @ 12:48
    Gordon Saxby
    0

    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

  • Gordon Saxby 1444 posts 1855 karma points
    Jan 15, 2015 @ 13:26
    Gordon Saxby
    0

    Can I see / have the code so that I can see if I can debug it?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 15, 2015 @ 13:29
    Jeavon Leopold
    0

    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

  • Gordon Saxby 1444 posts 1855 karma points
    Jan 16, 2015 @ 09:51
    Gordon Saxby
    0

    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:
    at Umbraco.Core.IO.PhysicalFileSystem.GetRelativePath(String fullPathOrUrl)
       at Our.Umbraco.CropHealer.CropHealer.GetMediaFileDimensions(String mediaItemUrl)
       at Our.Umbraco.CropHealer.CropHealer.HealContentItems(IEnumerable`1 content, IEnumerable`1 cropperContentProperties, List`1 dataTypeCrops, IDataTypeService dts, IContentService cs)
       at Our.Umbraco.CropHealer.CropHealer.SeekAndHeal(IDataTypeDefinition dataType, IDataTypeService dts)
       at Our.Umbraco.CropHealer.UmbracoEvents.DataTypeService_Saved(IDataTypeService sender, SaveEventArgs`1 e)
       at Umbraco.Core.Events.TypedEventHandler`2.Invoke(TSender sender, TEventArgs e)
       at Umbraco.Core.Services.DataTypeService.SaveDataTypeAndPreValues(IDataTypeDefinition dataTypeDefinition, IDictionary`2 values, Int32 userId)
       at Umbraco.Web.Editors.DataTypeController.PostSave(DataTypeSave dataType)
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)

     

    I checked that all the image files were present and I emptied the trash.

  • Gordon Saxby 1444 posts 1855 karma points
    Jan 16, 2015 @ 09:54
    Gordon Saxby
    0

    Unfortunately, I don't have time to debug on this project at the moment ... I will try and squeeze it it somehow / some time!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 16, 2015 @ 13:27
    Jeavon Leopold
    0

    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.

  • Sentient 10 posts 60 karma points
    Sep 01, 2015 @ 04:48
    Sentient
    0

    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).

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 01, 2015 @ 14:48
    Jeavon Leopold
    0

    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

  • Gordon Saxby 1444 posts 1855 karma points
    Jan 16, 2015 @ 14:13
    Gordon Saxby
    0

    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)
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 16, 2015 @ 14:52
    Jeavon Leopold
    0

    That's great! Is it doing the job of "healing" the other crops?

    Any other logs from CropHealer in the log file?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 16, 2015 @ 17:37
    Jeavon Leopold
    0

    I've updated the methods to skip unpopulated cropper properties in build 29 as they don't need healing but logged the skip action.

Please Sign in or register to post replies

Write your reply to:

Draft