ExifTool Forum

General => Metadata => Topic started by: xtu6 on August 01, 2024, 08:17:45 PM

Title: exif tags to crop image without modifying its underlying image data
Post by: xtu6 on August 01, 2024, 08:17:45 PM
Are there any exif tags to crop an image without modifying its underlying image data?

Say I have a JPEG where I want to crop out its top 5 rows, bottom 2 rows, and right 3 columns (leaving the left side uncropped).

I don't want to have to recompress it as a new JPEG with different image data, so I can avoid quality loss from the second lossy compression.

I don't want to have to save it as a lossless PNG because that will massively increase the file size.

I just want to embed some exif tags that instruct image libraries/programs to crop the image derived from the underlying image data (which remains unchanged) at the desired places.

Sort of like how the Orientation exif tag rotates an image without modifying the underlying image data.
Title: Re: exif tags to crop image without modifying its underlying image data
Post by: Phil Harvey on August 01, 2024, 09:26:28 PM
Unfortunately there aren't any tags that will do this for you.  Basically, the only EXIF tags that are honoured universally for image rendering are the colorspace and orientation tags.

- Phil
Title: Re: exif tags to crop image without modifying its underlying image data
Post by: xtu6 on August 01, 2024, 09:49:29 PM
Quote from: Phil Harvey on August 01, 2024, 09:26:28 PMthe only EXIF tags that are honoured universally
Are any proprietary crop tags honored by Apple software (like the Music app, and/or macOS Finder), but are not universally honored? I assume not, but I figured I'd ask just in case...

Thanks for the info.
Title: Re: exif tags to crop image without modifying its underlying image data
Post by: wywh on August 02, 2024, 04:46:27 AM
I have used GraphicConverter (Mac) to losslessly crop .jpg images. The crop must be done in 8 or sometimes 16 pixel increments.

- Matti
Title: Re: exif tags to crop image without modifying its underlying image data
Post by: StarGeek on August 02, 2024, 11:58:09 AM
Quote from: xtu6 on August 01, 2024, 09:49:29 PMAre any proprietary crop tags honored by Apple software (like the Music app, and/or macOS Finder), but are not universally honored? I assume not, but I figured I'd ask just in case...

I can't speak specifically for the Mac, but I have never seen any image viewer that will display a virtual crop, including several cross-platform programs.

There are some crop type tags in XMP, specifically in Adobe Camera Raw Defaults (https://exiftool.org/TagNames/XMP.html#crd) and Adobe Photoshop Camera Raw (https://exiftool.org/TagNames/XMP.html#crs) tags, but I believe these are mostly used in the editing history. They're not something I've ever seen any image viewer take into account.

To expand on @wywh's post, you can losslessly crop JPEGs on 8 pixel (sometimes 16 pixel) blocks on the left and top sides.  Crops on the right and bottom can be partial crops. There aren't very many programs that will do this for you, though.

I show an example in this post (https://exiftool.org/forum/index.php?msg=81836) where I combine the command line program jpegtran (https://en.wikipedia.org/w/index.php?title=Jpegtran) and ImageMagick to figure out the dimensions an image needs to be cropped to remove the border and then pass those dimensions to jpegtran.  The after image shows that there is still a bit of a border on the left and top, as the border edge did not fall upon an 8 pixel block size, but the bottom and right sides have been completely trimmed. This is a lossless operation.
Title: Re: exif tags to crop image without modifying its underlying image data
Post by: xtu6 on August 03, 2024, 01:16:11 AM
Thanks all for the info. I'll look into the `jpegtran` cropping hack.