The letter S, in dark yellow, in a curvy handrawn style Scribbles Updates
March 22nd, 2024

Image metadata

Updates

Over the past week, I got a few requests about better handling image metadata, especially preserving colour space and the profile, so those images really pop and look great... and as intended.

By default Scribbles always strips image metadata. The reason for this is simple, GPS data. It's not enough to presume that you will remove this yourself, although I am of the opinion that it is your choice — but sometimes people just forget. I've seen this with some blog images, so that's why I've added the metadata strip.

Unfortunately that also has the unintended side effect of sometimes just making the image look... drab.

One evening this week I set about to try and handle this — but came across limits of the framework (Ruby on Rails). Let me explain.

When an image is uploaded, it will use something called Active Storage to handle image uploading. It's magic and just works. It'll take your original image, as intended, and just upload it with all the data intact. At the same time, it will create a "checksum" of that image, meaning that if it is ever tampered with, outside of the application, it will refuse to render it. Good stuff, and just what you want.

On the front end of things, I do some extra bits to then resize your image... basically creating variations of your image. Here is the code if you're interested (super simple):

<%= image_tag cdn_image_url(blob.representation(resize_to_limit: [ 2048, 1536 ], saver: { strip: true, quality: 95 })), srcset: "\#{cdn_image_url(blob.representation(resize_to_limit: [ 4096, 3072 ], saver: { strip: true, quality: 95 }))} 2x", loading: "lazy", alt: !blob.try(:caption).nil? ? blob.try(:caption) : nil  %>

That creates 2 images with different sizes. The important part here is the "saver" option:

saver: { strip: true, quality: 95 }

Passing in "strip: true" will strip any metadata of the image, including that all inclusive GPS data if it's present. I wish it was more flexible and would allow you to pass in options to only strip certain data — but there isn't. It's not supported.

But as you've guessed that causes issues with stripping important metadata like the colour profile.

So I wrote a little service that listens for file changes in the image directory, and then take that image and just remove the GPS location metadata. It worked a treat and was just automatic as soon as the image was uploaded.

Unfortunately that caused a major issue. Because I now tampered with the image, the checksum also changes — so Scribbles just refuses to render it. So now I have opened a can of worms, where I would have to try and do this on the application level... but that opened up even more cans. So 5 hours later, and 2 days of thinking time... I came up with an easy solution that doesn't add convoluted code and a massive headache — and yes, I tried running it through the CDN, but they also stripped all metadata. Anyway...

New image metadata option

Now you have a new Nitpick option on your blog, that allows you to disable metadata stripping. It's enabled by default so that it has the intended behaviour of stripping it.

You can disable image metadata stripping if needed in Nitpick settings.
You can disable image metadata stripping if needed in Nitpick settings.

I know image metadata is important to a few of you, so I wanted to make sure to give you an option — I know what you're doing and that you're aware of the complications of metadata.

For most, you don't need to change this setting, but for those that want the absolute best representation of your image, you now have an option.

Edit: I am researching methods of stripping this data automatically before uploading. The above is mainly a stopgap measure that should work for most if you want it to.

powered by scribbles