I have two copies of the same image (jpeg). One is 4.0 MB the other 5.9 MB.
I have run
exiftool -a -G1 -s
and the only difference reported is the size.
I used hexdump to compare them and they seem to be identical except the second has more data at the end.
They did originally come from an an old Mac and one had extended attributes, including
com.apple.ResourceFork 118660
Does that mean the added data is a resource fork? Is it anything sinister?
I deleted the extended attribute using
xattr -d com.apple.ResourceFork image2.jpg
but that made no difference to the size of the file.
Why are the two files different sizes? I have other files like this. How do I get rid of the junk data at the end of the file?
With some more experimenting I did the following. Using the OS X utility sips
sips -s format jpeg image2.jpg --out image0.jpg
reduced the file size to 2MB, but the quality was reduced from 96% to 93%, so I assume that some extra compression happened.
With
sips -f horizontal image2.jpg ; sips -f horizontal image2.jpg
reduced the file size to 2MB (but a tiny bit smaller than image0.jpg), but the quality was reduced from 96% to 93%.
With the ImageMagick tool
convert image2.jpg image4.jpg
reduced the file size to 3.8MB, the quality was maintained at 96%.
It seems all these tools alter the image in some way, maybe by applying a compression algorithm again. Can exiftool help work out what's going on?
ExifTool should report a ResourceForkSize if the file has a resource fork. The reported FileSize does not include the resource fork.
Using ExifTool you can get rid of junk data at the end of the file with:
exiftool -trailer:all= FILE
Are you sure it is just a metadata difference between the files? You can tell if it is by removing all metadata from both files (exiftool -all= FILE) then comparing them.
- Phil
Since you mentioned ImageMagick, try using this command (changing Image1/2.jpg to the actual images)
Compare Image1.jpg Image2.jpg Difference.png
If there is any red in Difference.png, then the two images are different, probably the result of recompressing a jpeg. The hard part is figuring out which image is closer to the original.
Quote from: Phil Harvey on December 31, 2016, 05:33:33 PM
Using ExifTool you can get rid of junk data at the end of the file with:
exiftool -trailer:all= FILE
Ah! That was the command I was looking for. When I trim the larger file, it is exactly the same size as the smaller file.
Quote from: StarGeek on December 31, 2016, 11:04:35 PM
Since you mentioned ImageMagick, try using this command (changing Image1/2.jpg to the actual images)
Compare Image1.jpg Image2.jpg Difference.png
But then comparing the two files, there are some differences between them, which is odd because as far as I could tell, looking at individual bytes, there were identical up to the point where the 'trailer' began. The difference image was a very faint version of the original.
Thanks for your help.
Quote from: pheon on January 01, 2017, 12:41:38 PM
Quote from: StarGeek on December 31, 2016, 11:04:35 PM
Since you mentioned ImageMagick, try using this command (changing Image1/2.jpg to the actual images)
Compare Image1.jpg Image2.jpg Difference.png
But then comparing the two files, there are some differences between them, which is odd because as far as I could tell, looking at individual bytes, there were identical up to the point where the 'trailer' began. The difference image was a very faint version of the original.
If it wasn't red, then it was the exact same pixel. You'll still faintly see the original image, but where it's white, it's identical, where it's red, it's different. Example image (https://i.stack.imgur.com/OM6V1.png).
So it sounds like you were right in the first place, identical images with something else added.