sharp icon indicating copy to clipboard operation
sharp copied to clipboard

How to write GPS data using withMetadata

Open thiagupct opened this issue 4 years ago • 2 comments

What are you trying to achieve? Am trying to write GPS data to an image but I can't get it work, Any help is highly appreciated

Have you searched for similar questions? Yes, I have searched but haven't found any examples

Are you able to provide a minimal, standalone code sample that demonstrates this question?

const image = sharp("./logo.jpg");
image
.withMetadata({ 
	exif: {
		IFD3: { 
			GPSLatitudeRef: "N",
			GPSLatitude: "55/1 43/1 5287/100",
			GPSLongitudeRef: "E",
			GPSLongitude: "37/1 35/1 5571/100",
			GPSAltitudeRef: "Sea level",
			GPSAltitude: "90514/693",
			GPSSpeedRef: "K",
			GPSSpeed: "114272/41081",
			GPSImgDirectionRef: "M",
			GPSImgDirection: "192127/921",
			GPSDestBearingRef: "M",
			GPSDestBearing: "192127/921",
			GPSDateStamp: "2020:07:28",
		}
	} 
})
.toFile('output1.jpg')
.then(info => { 
	console.log(info);
})
.catch(err => { 
	console.log(err);
});

Are you able to provide a sample image that helps explain the question? image

thiagupct avatar Jun 23 '21 23:06 thiagupct

Hi, it look like libexif (used by libvips) considers the tags in the GPS "subdirectory" to be EXIF_FORMAT_UNDEFINED. This means libvips does not currently know how to write them, hence the empty Buffer instances you're seeing.

We'll probably need to make libvips aware of all the possible formats (rational, string etc.) of the various GPS tags listed at https://exiftool.org/TagNames/GPS.html

lovell avatar Jun 26 '21 17:06 lovell

I just opened PR https://github.com/libvips/libvips/pull/2966 for this. With that, and the above example, I see:

$ vipsheader -a x.jpg | grep exif-ifd3-GPS
exif-ifd3-GPSLatitudeRef: N (N, ASCII, 2 components, 2 bytes)
exif-ifd3-GPSLatitude: 55/1 43/1 5287/100 (55, 43, 52.87, Rational, 3 components, 24 bytes)
exif-ifd3-GPSLongitudeRef: E (E, ASCII, 2 components, 2 bytes)
exif-ifd3-GPSLongitude: 37/1 35/1 5571/100 (37, 35, 55.71, Rational, 3 components, 24 bytes)
exif-ifd3-GPSAltitudeRef: Sea level (Sea level, Byte, 1 components, 1 bytes)
exif-ifd3-GPSAltitude: 90514/693 (130.612, Rational, 1 components, 8 bytes)
exif-ifd3-GPSSpeedRef: K (K, ASCII, 2 components, 2 bytes)
exif-ifd3-GPSSpeed: 114272/41081 (2.78163, Rational, 1 components, 8 bytes)
exif-ifd3-GPSImgDirectionRef: M (M, ASCII, 2 components, 2 bytes)
exif-ifd3-GPSImgDirection: 192127/921 (208.607, Rational, 1 components, 8 bytes)
exif-ifd3-GPSDestBearingRef: M (M, ASCII, 2 components, 2 bytes)
exif-ifd3-GPSDestBearing: 192127/921 (208.607, Rational, 1 components, 8 bytes)
exif-ifd3-GPSDateStamp: 2020:07:28 (2020:07:28, ASCII, 11 components, 11 bytes)

kleisauke avatar Jul 30 '22 14:07 kleisauke

sharp v0.32.0 is now available with prebuilt binaries that include libvips v8.14.2.

lovell avatar Mar 24 '23 18:03 lovell