Jump to content

Client-side image resize - EXIF and IPCT metadata loss


dalibor
 Share

Recommended Posts

I'm using hook for retrieving data from image metadata (IPTC) after image upload and filling them to some fields. When I choose server-side image resize, everything works well. But when I use client-side resize (which si much faster and client comfortable  - it uses PWImageResizer.js) image metadata are lost during resizing - I have downloaded the file after resize and checked for EXIF, IPTC etc. and they are not present.  Using PW 3.0.165. Tried to look into PWImageResizer.js but uhh it's too javascreepy to me:) 

Link to comment
Share on other sites

Interesting question, I've had a look at PWImageResizer.js, apparently this wasn't built with retention of EXIF data in mind. Take a look at the source code of the scaleImage function: It uses a canvas to draw the image on it, then resizes it according to the maximum width/height settings (including some fancy math to scale the image). The canvas is then turned into a data URI using HTMLCanvasElement.toDataURL() and which is then parsed back to a Blob (binary image data). The intermediary canvas can't hold EXIF metadata, so it is lost during that step. If you wanted to retain EXIF data, the script would need to read it from the original image and add it back to the final Blob / binary data. This SO thread has some examples of how to do that. Not sure if you can add it to the image inputfield from outside, it would probably need to be added to the core. Maybe open a feature request for that, though you should be aware that this is not trivial if the script needs to handle all kinds of edge-cases and support legacy browsers ...

  • Like 2
Link to comment
Share on other sites

8 hours ago, dalibor said:

When I choose server-side image resize, everything works well. But when I use client-side resize (which si much faster and client comfortable  - it uses PWImageResizer.js) image metadata are lost during resizing

Both client-side and server-side resizing strip the EXIF data. If you are able to get the EXIF data with the server-side option then possibly you are hooking before the resize and might be able to access and save the EXIF data then. But in my opinion PW shouldn't be stripping any data from an uploaded image that is to be the "original" from which variations are derived.

There's an open issue about this, with fixes for both client-side and server-side resizing (ImageMagick only): https://github.com/processwire/processwire-issues/issues/1055
Just hoping and waiting for it to be applied to the core...

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...