How to export Preview jpeg at a specific kb size?

I've seen it, but it requires loading the whole file into a clipboard. Right? Whereas this method looks like it doesn't, which may make it 100 times faster.

The KM action simply processes the image already in memory whereas sips first reads the image file into memory and then after processing writes the result out to a file so they're not directly comparable when it comes to speed.

Oh. I had expected that sips could edit the portion of the file containing the DPI without reading the whole file. Sometimes files have certain data in the first kilobyte that can be edited/modified without reading the whole file.

Remember that the JPEG format itself has no concept of DPI -- the horizontal and vertical pixel dimensions are stated for the image, but there's nothing to say how big those pixels are.

DPI is provided by the Exif metadata. That's held in the APP1 segment of the JPEG header, and the particular Exif tags concerned are "X resolution" and "Y resolution".

I don't know if sips is able to edit the Exif resolution tags without reading then writing the whole file (but I think it unlikely, that's not what it was made to do). You've more chance of doing it with a tool actually designed for editing Exif data -- we've done a bit with exiftool on the Forum, there might be more if you search, otherwise there's plenty of examples on the web.

1 Like