libvips / php-vips-ext

Low-level libvips binding for PHP
MIT License
101 stars 11 forks source link

Get EXIF value by field name #9

Closed uasan closed 7 years ago

uasan commented 7 years ago
<?php

$img = vips_image_new_from_file('/opt/exif.jpg')['out']?? null;

$data = vips_image_get($img, 'exif-Model'); // return -1
$data = vips_image_get($img, 'exif-data'); // return ['out' => "all fields as raw string 50 Kb"]

How to get EXIF value by field name? Thank.

jcupitt commented 7 years ago

You need to put in the ifd as well, for example exif-ifd2-MakerNote.

You can list all the fields on an image with:

$  vipsheader -a IMG_4618.jpg 
IMG_4618.jpg: 1024x768 uchar, 3 bands, srgb, jpegload
width: 1024
height: 768
bands: 3
format: uchar
coding: none
interpretation: srgb
xoffset: 0
yoffset: 0
xres: 7.08661
yres: 7.08661
filename: IMG_4618.jpg
vips-loader: jpegload
jpeg-multiscan: 0
exif-data: 6626 bytes of binary data
icc-profile-data: 1352 bytes of binary data
resolution-unit: in
exif-ifd0-ImageDescription:                                 (                               , ASCII, 32 components, 32 bytes)
exif-ifd0-Make: Canon (Canon, ASCII, 6 components, 6 bytes)
exif-ifd0-Model: Canon PowerShot S90 (Canon PowerShot S90, ASCII, 20 components, 20 bytes)
exif-ifd0-Orientation: 1 (Top-left, Short, 1 components, 2 bytes)
exif-ifd0-XResolution: 11796480/65536 (180.00000, Rational, 1 components, 8 bytes)
exif-ifd0-YResolution: 11796480/65536 (180.00000, Rational, 1 components, 8 bytes)
etc. etc. 

I would use php-vips rather than the binary module, I guess you know.

jcupitt commented 7 years ago

Did you see php-vips?

https://github.com/jcupitt/php-vips

It's a fairly high-level php binding over this low-level binary module. API docs here:

https://jcupitt.github.io/php-vips/docs/classes/Jcupitt.Vips.Image.html

uasan commented 7 years ago

Thanks It works!

Did you see php-vips?

Yes, i saw, but I'm doing a low-level PHP worker, which should work async. Thank.