Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Does ruby-vips update exif metadata on save? #313

Answered by jcupitt
zorar4ik asked this question in Q&A
Discussion options

Hi, I faced odd situation with converting images with different exif orientation. For example I am trying to strip metadata on save for image
raw image: raw_image.get('exif-ifd0-Orientation') => 5 (Left-top, Short, 1 components, 2 bytes)
RAW
portrait_5
RAW

processed image: image.get('exif-ifd0-Orientation') => 1 (Top-left, Short, 1 components, 2 bytes)
PROCESSED
preview_1000_photo
PROCESSED

I thought It should completely remove exif metadata
am I doing something wrong or it is proper behaviour? Thanks in advance

You must be logged in to vote

Hi @zorar4ik,

It should work. Please post a complete runnable program and a test image that illustrates the problem so I can reproduce it.

Replies: 1 comment 6 replies

Comment options

Hi @zorar4ik,

It should work. Please post a complete runnable program and a test image that illustrates the problem so I can reproduce it.

You must be logged in to vote
6 replies
Comment options

@jcupitt thanks for quick response! One more quick question then. How to test properly that strip method has been used? I mean what kind of metadata has been erased?

Comment options

Ooop, sorry, my mistake, it removes EXIF too.

The EXIF you see when you reload is the minimal amount of exif necessary for an image to be in spec, and it attached by the loader if the image has no exif.

$ vipsheader -a k2.jpg | grep exif-data
exif-data: 186 bytes of binary data
$ vips copy k2.jpg x.jpg[strip]
$ vipsheader -a x.jpg
x.jpg: 1450x2048 uchar, 3 bands, srgb, jpegload
width: 1450
height: 2048
bands: 3
format: uchar
coding: none
interpretation: srgb
xoffset: 0
yoffset: 0
xres: 2.83465
yres: 2.83465
filename: x.jpg
vips-loader: jpegload
jpeg-multiscan: 0
jpeg-chroma-subsample: 4:2:0

You can see there's no exif on x.jpg.

Comment options

Hmm, I am a bit confused then. So strip should remove all exif metadata, isn't it? So why does my saved file has exif metadata? In fact it seems that amount of metadata has increased after saving to file.

Comment options

I don't think your saved file does have exif metadata, does it? I see:

$ irb
irb(main):001:0> require 'vips'
=> true
irb(main):002:0> x = Vips::Image.new_from_file("k2.jpg")
=> #<Image 1450x2048 uchar, 3 bands, srgb>
irb(main):003:0> x.write_to_file("x.jpg", strip: true)
=> nil
irb(main):004:0> 
$ vipsheader -a x.jpg
x.jpg: 1450x2048 uchar, 3 bands, srgb, jpegload
width: 1450
height: 2048
bands: 3
format: uchar
coding: none
interpretation: srgb
xoffset: 0
yoffset: 0
xres: 2.83465
yres: 2.83465
filename: x.jpg
vips-loader: jpegload
jpeg-multiscan: 0
jpeg-chroma-subsample: 4:2:0

No EXIF.

If I load and save again:

$ irb
irb(main):001:0> require 'vips'
=> true
irb(main):002:0> x = Vips::Image.new_from_file("x.jpg")
=> #<Image 1450x2048 uchar, 3 bands, srgb>
irb(main):003:0> x.write_to_file("x2.jpg")
=> nil
irb(main):004:0> 
$ vipsheader -a x2.jpg
x2.jpg: 1450x2048 uchar, 3 bands, srgb, jpegload
width: 1450
height: 2048
bands: 3
format: uchar
coding: none
interpretation: srgb
xoffset: 0
yoffset: 0
xres: 2.83465
yres: 2.83465
filename: x2.jpg
vips-loader: jpegload
jpeg-multiscan: 0
jpeg-chroma-subsample: 4:2:0
exif-data: 186 bytes of binary data
resolution-unit: in
exif-ifd0-Orientation: 1 (Top-left, Short, 1 components, 2 bytes)
exif-ifd0-XResolution: 72/1 (72, Rational, 1 components, 8 bytes)
exif-ifd0-YResolution: 72/1 (72, Rational, 1 components, 8 bytes)
exif-ifd0-ResolutionUnit: 2 (Inch, Short, 1 components, 2 bytes)
exif-ifd0-YCbCrPositioning: 1 (Centred, Short, 1 components, 2 bytes)
exif-ifd2-ExifVersion: Exif Version 2.1 (Exif Version 2.1, Undefined, 4 components, 4 bytes)
exif-ifd2-ComponentsConfiguration: Y Cb Cr - (Y Cb Cr -, Undefined, 4 components, 4 bytes)
exif-ifd2-FlashpixVersion: FlashPix Version 1.0 (FlashPix Version 1.0, Undefined, 4 components, 4 bytes)
exif-ifd2-ColorSpace: 65535 (Uncalibrated, Short, 1 components, 2 bytes)
exif-ifd2-PixelXDimension: 1450 (1450, Long, 1 components, 4 bytes)
exif-ifd2-PixelYDimension: 2048 (2048, Long, 1 components, 4 bytes)
orientation: 1

Now there's EXIF, because this time the JPEG saver hasn't been given the strip option, so it's attached the minimal set of EXIF necessary to meet the spec.

Comment options

@jcupitt thanks. Now I see the point. So images with exif orientation different from 1 will be rotated and saved with new exif orientation tag. But with proper strip option there will be no exif metadata at all. So it means that strip didn't work when I called it. But that's a different story. Thanks for your support and for amazing work on this library

Answer selected by zorar4ik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /