Code Monkey home page Code Monkey logo

Comments (7)

jcupitt avatar jcupitt commented on May 17, 2024

I've been experimenting here and I don't see problems quite as bad as the ones you have.

For example, before processing:

$ exif img_0075.jpg 
EXIF tags in 'img_0075.jpg' ('Intel' byte order):
--------------------+----------------------------------------------------------
Tag                 |Value
--------------------+----------------------------------------------------------
Manufacturer        |Canon
Model               |Canon DIGITAL IXUS 300
Orientation         |Top-left
X-Resolution        |180
Y-Resolution        |180
Resolution Unit     |Inch
Date and Time       |2001:10:22 10:00:09
YCbCr Positioning   |Centred
Compression         |JPEG compression
X-Resolution        |180
Y-Resolution        |180
Resolution Unit     |Inch
Exposure Time       |1/800 sec.
F-Number            |f/4.7
Exif Version        |Exif Version 2.1
Date and Time (Origi|2001:10:22 10:00:09
Date and Time (Digit|2001:10:22 10:00:09
Components Configura|Y Cb Cr -
Compressed Bits per | 2
Shutter Speed       |9.66 EV (1/806 sec.)
Aperture            |4.53 EV (f/4.8)
Exposure Bias       |0.00 EV
Maximum Aperture Val|2.87 EV (f/2.7)
Subject Distance    |65.5 m
Metering Mode       |Pattern
Flash               |Flash did not fire
Focal Length        |16.2 mm
Maker Note          |410 bytes undefined data
User Comment        |
FlashPixVersion     |FlashPix Version 1.0
Colour Space        |sRGB
Pixel X Dimension   |1600
Pixel Y Dimension   |1200
Focal Plane X-Resolu|7766.990
Focal Plane Y-Resolu|7741.935
Focal Plane Resoluti|Inch
Sensing Method      |One-chip colour area sensor
File Source         |DSC
Interoperability Ind|R98
Interoperability Ver|0100
RelatedImageWidth   |1600
RelatedImageLength  |1200
--------------------+----------------------------------------------------------
EXIF data contains a thumbnail (4098 bytes).

And after:

$ exif tn_img_0075.jpg 
EXIF tags in 'tn_img_0075.jpg' ('Intel' byte order):
--------------------+----------------------------------------------------------
Tag                 |Value
--------------------+----------------------------------------------------------
Manufacturer        |Canon
Model               |Canon DIGITAL IXUS 300
Orientation         |Top-left
X-Resolution        |180.00000000
Y-Resolution        |180.00000000
Resolution Unit     |Inch
Date and Time       |2001:10:22 10:00:09
YCbCr Positioning   |Centred
Compression         |JPEG compression
X-Resolution        |180.00000000
Y-Resolution        |180.00000000
Resolution Unit     |Inch
Exposure Time       |1/800 sec.
F-Number            |f/4.7
Exif Version        |Exif Version 2.1
Date and Time (Origi|2001:10:22 10:00:09
Date and Time (Digit|2001:10:22 10:00:09
Components Configura|Y Cb Cr -
Compressed Bits per |2.0000000000
Shutter Speed       |9.66 EV (1/806 sec.)
Aperture            |4.53 EV (f/4.8)
Exposure Bias       |-0.00 EV
Maximum Aperture Val|2.87 EV (f/2.7)
Subject Distance    |65.5 m
Metering Mode       |Pattern
Flash               |Flash did not fire
Focal Length        |16.2 mm
Maker Note          |410 bytes undefined data
User Comment        |
FlashPixVersion     |FlashPix Version 1.0
Colour Space        |sRGB
Pixel X Dimension   |1600
Pixel Y Dimension   |1200
Focal Plane X-Resolu|7766.990291
Focal Plane Y-Resolu|7741.935483
Focal Plane Resoluti|Inch
Sensing Method      |One-chip colour area sensor
File Source         |DSC
Interoperability Ind|R98
Interoperability Ver|0100
RelatedImageWidth   |1600
RelatedImageLength  |1200
--------------------+----------------------------------------------------------
EXIF data contains a thumbnail (4098 bytes).

Could you send me a (small!) crop of the image that's not working for you? Perhaps there's something strange about it.

For reference, here's how jpegload handles metadata:

  • image resolution set from JFIF, if JFIF has it
  • the first XMP block in APP1 is loaded and attached to the output image
  • the first Exif block is read and attached to the output image
  • all APP2 ICC blocks are read, concatenated, and attached
  • the exif block is parsed and fields attached to the image named as "exif-tagname", for example "exif-X-Resolution"
  • the value of each field is the unlocalised value converted to ascii, followed by some descriptive text in brackets, for example
  • if there's an exif tag for X-Resolution, the image resolution is set from that, overriding any JFIF resolution

You can see all this if you try "header -a file.jpg", it'll show all the tags vips has read.

On save, the opposite happens. The metadata is reconstructed from the exif- fields and reattached.

from libvips.

ferryfax avatar ferryfax commented on May 17, 2024

Thanks for looking into it. I've sent you a sample of what I've seen.

from libvips.

jcupitt avatar jcupitt commented on May 17, 2024

Here are a few improvements to exif handling:

jcupitt@fcc3302

The negative numbers you are seeing for xres/yres are a minor bug in jpegsnoop. vips is setting a very large numerator/denominator values in an attempt to approximate a floating point number, and jpegsnoop is overflowing. It's using a signed int for an unsigned int rational.

Try with exiftool and you should see the correct value.

Unfortunately I've had to change the way exif names are converted to vips metadata names and this might break some other programs. This change will probably have to wait for the next version of libvips, due in a month or two.

from libvips.

jcupitt avatar jcupitt commented on May 17, 2024

Another patch, this keeps rationals as a/b. Generating a sane rational from a double is too annoying.

jcupitt@74f545f

from libvips.

ferryfax avatar ferryfax commented on May 17, 2024

Thanks John, much appreciated.

If you are changing the Exif code maybe something else to do is to update the ExifImageWidth and ExifImageHeight so it reflects the new size after a re-sizing. Or is that something the calling application should do?

from libvips.

jcupitt avatar jcupitt commented on May 17, 2024

Here are some more patches. First, update ExifImageWidth and Height:

jcupitt@43e1cda

And allow int-valued fields to be in any format:

jcupitt@7025fe4

from libvips.

jcupitt avatar jcupitt commented on May 17, 2024

Three more patches, and it's all done: copy over ipct tag, be less fussy about data-less exif, some cleanups.

jcupitt@c3ef2be
jcupitt@65b4056
jcupitt@20ce700

from libvips.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.