I am trying to create .jpg files that can be consumed on the web from a .tif image. I would like to rely on EXIF data about the image metadata, however, I fail to read any. What am I doing wrong?

$ gdal_translate --version
GDAL 3.0.4, released 2020/01/28

$ gdalwarp -t_srs EPSG:4326 IW32001452_mask.tif /tmp/tif2jpeg.tif
Creating output file that is 1802P x 1244L.
Processing IW32001452_mask.tif [1/1] : 0...10...20...30...40...50...60...70...80...90...100 - done.

$ gdal_translate -of JPEG -scale -co write_exif_metadata=yes /tmp/tif2jpeg.tif IW32001452_mask.jpg
Input file size is 1802, 1244
0...10...20...30...40...50...60...70...80...90...100 - done.

$ exif IW32001452_mask.jpg
Corrupt data
The data provided does not follow the specification.
ExifLoader: The data supplied does not seem to contain EXIF data.

GDAL does not invent the EXIF metadata for you. When you run

gdalwarp -t_srs EPSG:4326 IW32001452_mask.tif /tmp/tif2jpeg.tif

if IW32001452_mask.tif does not contain EXIF tags then tif2jpeg.tif does not have them either and even -co write_exif_metadata=yesprepares the JPEG file to include EXIF metadata, if there does not exist any tags to write then there will be no EXIF metadata.

If source data does not have EXIF tags to be copied you can insert them manually. As an example the EXIF tag XResolution is set this way:

gdal_translate gdal.png -mo EXIF_XResolution=180 gdal.jpg

You can check the result with gdalinfo

gdalinfo gdal.jpg
Files: gdal.jpg
Size is 4000, 3000
Coordinate System is `'

or with some EXIF tool, for example exiftool:

exiftool gdal.jpg
ExifTool Version Number         : 12.07
File Name                       : gdal.jpg
Y Resolution                    : 1
Exif Byte Order                 : Little-endian (Intel, II)
X Resolution                    : 180

You can see that Y Resolution is 1, the default, but X Resolution 180 just as it was set with gdal_translate.

  • Thanks a lot! I thought there is some kind of magic that puts the meta, thanks for the explanation! – suricactus Oct 6 '20 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.