Merge pull request #346 from fredeastside/more_exif_data

add most useful exif data to metadata
This commit is contained in:
Tom 2020-08-04 20:02:48 +02:00 committed by GitHub
commit f5e58f04a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 429 additions and 70 deletions

View file

@ -6,6 +6,60 @@ package bimg
*/
import "C"
const (
Make = "exif-ifd0-Make"
Model = "exif-ifd0-Model"
Orientation = "exif-ifd0-Orientation"
XResolution = "exif-ifd0-XResolution"
YResolution = "exif-ifd0-YResolution"
ResolutionUnit = "exif-ifd0-ResolutionUnit"
Software = "exif-ifd0-Software"
Datetime = "exif-ifd0-DateTime"
YCbCrPositioning = "exif-ifd0-YCbCrPositioning"
Compression = "exif-ifd1-Compression"
ExposureTime = "exif-ifd2-ExposureTime"
FNumber = "exif-ifd2-FNumber"
ExposureProgram = "exif-ifd2-ExposureProgram"
ISOSpeedRatings = "exif-ifd2-ISOSpeedRatings"
ExifVersion = "exif-ifd2-ExifVersion"
DateTimeOriginal = "exif-ifd2-DateTimeOriginal"
DateTimeDigitized = "exif-ifd2-DateTimeDigitized"
ComponentsConfiguration = "exif-ifd2-ComponentsConfiguration"
ShutterSpeedValue = "exif-ifd2-ShutterSpeedValue"
ApertureValue = "exif-ifd2-ApertureValue"
BrightnessValue = "exif-ifd2-BrightnessValue"
ExposureBiasValue = "exif-ifd2-ExposureBiasValue"
MeteringMode = "exif-ifd2-MeteringMode"
Flash = "exif-ifd2-Flash"
FocalLength = "exif-ifd2-FocalLength"
SubjectArea = "exif-ifd2-SubjectArea"
MakerNote = "exif-ifd2-MakerNote"
SubSecTimeOriginal = "exif-ifd2-SubSecTimeOriginal"
SubSecTimeDigitized = "exif-ifd2-SubSecTimeDigitized"
ColorSpace = "exif-ifd2-ColorSpace"
PixelXDimension = "exif-ifd2-PixelXDimension"
PixelYDimension = "exif-ifd2-PixelYDimension"
SensingMethod = "exif-ifd2-SensingMethod"
SceneType = "exif-ifd2-SceneType"
ExposureMode = "exif-ifd2-ExposureMode"
WhiteBalance = "exif-ifd2-WhiteBalance"
FocalLengthIn35mmFilm = "exif-ifd2-FocalLengthIn35mmFilm"
SceneCaptureType = "exif-ifd2-SceneCaptureType"
GPSLatitudeRef = "exif-ifd3-GPSLatitudeRef"
GPSLatitude = "exif-ifd3-GPSLatitude"
GPSLongitudeRef = "exif-ifd3-GPSLongitudeRef"
GPSLongitude = "exif-ifd3-GPSLongitude"
GPSAltitudeRef = "exif-ifd3-GPSAltitudeRef"
GPSAltitude = "exif-ifd3-GPSAltitude"
GPSSpeedRef = "exif-ifd3-GPSSpeedRef"
GPSSpeed = "exif-ifd3-GPSSpeed"
GPSImgDirectionRef = "exif-ifd3-GPSImgDirectionRef"
GPSImgDirection = "exif-ifd3-GPSImgDirection"
GPSDestBearingRef = "exif-ifd3-GPSDestBearingRef"
GPSDestBearing = "exif-ifd3-GPSDestBearing"
GPSDateStamp = "exif-ifd3-GPSDateStamp"
)
// ImageSize represents the image width and height values
type ImageSize struct {
Width int
@ -30,8 +84,54 @@ type EXIF struct {
Make string
Model string
Orientation int
XResolution string
YResolution string
ResolutionUnit int
Software string
Datetime string
YCbCrPositioning int
Compression int
ExposureTime string
FNumber string
ExposureProgram int
ISOSpeedRatings int
ExifVersion string
DateTimeOriginal string
DateTimeDigitized string
ComponentsConfiguration string
ShutterSpeedValue string
ApertureValue string
BrightnessValue string
ExposureBiasValue string
MeteringMode int
Flash int
FocalLength string
SubjectArea string
MakerNote string
SubSecTimeOriginal string
SubSecTimeDigitized string
ColorSpace int
PixelXDimension int
PixelYDimension int
SensingMethod int
SceneType string
ExposureMode int
WhiteBalance int
FocalLengthIn35mmFilm int
SceneCaptureType int
GPSLatitudeRef string
GPSLatitude string
GPSLongitudeRef string
GPSLongitude string
GPSAltitudeRef string
GPSAltitude string
GPSSpeedRef string
GPSSpeed string
GPSImgDirectionRef string
GPSImgDirection string
GPSDestBearingRef string
GPSDestBearing string
GPSDateStamp string
}
// Size returns the image size by width and height pixels.
@ -73,7 +173,7 @@ func Metadata(buf []byte) (ImageMetadata, error) {
Height: int(image.Ysize),
}
orientation := vipsExifOrientation(image)
orientation := vipsExifIntTag(image, Orientation)
metadata := ImageMetadata{
Size: size,
@ -84,11 +184,57 @@ func Metadata(buf []byte) (ImageMetadata, error) {
Space: vipsSpace(image),
Type: ImageTypeName(imageType),
EXIF: EXIF{
Make: vipsExifMake(image),
Model: vipsExifModel(image),
Make: vipsExifStringTag(image, Make),
Model: vipsExifStringTag(image, Model),
Orientation: orientation,
Software: vipsExifSoftware(image),
Datetime: vipsExifDatetime(image),
XResolution: vipsExifStringTag(image, XResolution),
YResolution: vipsExifStringTag(image, YResolution),
ResolutionUnit: vipsExifIntTag(image, ResolutionUnit),
Software: vipsExifStringTag(image, Software),
Datetime: vipsExifStringTag(image, Datetime),
YCbCrPositioning: vipsExifIntTag(image, YCbCrPositioning),
Compression: vipsExifIntTag(image, Compression),
ExposureTime: vipsExifStringTag(image, ExposureTime),
FNumber: vipsExifStringTag(image, FNumber),
ExposureProgram: vipsExifIntTag(image, ExposureProgram),
ISOSpeedRatings: vipsExifIntTag(image, ISOSpeedRatings),
ExifVersion: vipsExifStringTag(image, ExifVersion),
DateTimeOriginal: vipsExifStringTag(image, DateTimeOriginal),
DateTimeDigitized: vipsExifStringTag(image, DateTimeDigitized),
ComponentsConfiguration: vipsExifStringTag(image, ComponentsConfiguration),
ShutterSpeedValue: vipsExifStringTag(image, ShutterSpeedValue),
ApertureValue: vipsExifStringTag(image, ApertureValue),
BrightnessValue: vipsExifStringTag(image, BrightnessValue),
ExposureBiasValue: vipsExifStringTag(image, ExposureBiasValue),
MeteringMode: vipsExifIntTag(image, MeteringMode),
Flash: vipsExifIntTag(image, Flash),
FocalLength: vipsExifStringTag(image, FocalLength),
SubjectArea: vipsExifStringTag(image, SubjectArea),
MakerNote: vipsExifStringTag(image, MakerNote),
SubSecTimeOriginal: vipsExifStringTag(image, SubSecTimeOriginal),
SubSecTimeDigitized: vipsExifStringTag(image, SubSecTimeDigitized),
ColorSpace: vipsExifIntTag(image, ColorSpace),
PixelXDimension: vipsExifIntTag(image, PixelXDimension),
PixelYDimension: vipsExifIntTag(image, PixelYDimension),
SensingMethod: vipsExifIntTag(image, SensingMethod),
SceneType: vipsExifStringTag(image, SceneType),
ExposureMode: vipsExifIntTag(image, ExposureMode),
WhiteBalance: vipsExifIntTag(image, WhiteBalance),
FocalLengthIn35mmFilm: vipsExifIntTag(image, FocalLengthIn35mmFilm),
SceneCaptureType: vipsExifIntTag(image, SceneCaptureType),
GPSLatitudeRef: vipsExifStringTag(image, GPSLatitudeRef),
GPSLatitude: vipsExifStringTag(image, GPSLatitude),
GPSLongitudeRef: vipsExifStringTag(image, GPSLongitudeRef),
GPSLongitude: vipsExifStringTag(image, GPSLongitude),
GPSAltitudeRef: vipsExifStringTag(image, GPSAltitudeRef),
GPSAltitude: vipsExifStringTag(image, GPSAltitude),
GPSSpeedRef: vipsExifStringTag(image, GPSSpeedRef),
GPSSpeed: vipsExifStringTag(image, GPSSpeed),
GPSImgDirectionRef: vipsExifStringTag(image, GPSImgDirectionRef),
GPSImgDirection: vipsExifStringTag(image, GPSImgDirection),
GPSDestBearingRef: vipsExifStringTag(image, GPSDestBearingRef),
GPSDestBearing: vipsExifStringTag(image, GPSDestBearing),
GPSDateStamp: vipsExifStringTag(image, GPSDateStamp),
},
}