How to get image exif data?
Hi @jcupitt ,
Hope you are doing well, thanks for this awesome implementation.
I have some quetions, It would be great if you can help me to achieve those.
I have started implementing this in my PHP web application ( https://github.com/libvips/php-vips ) I have loaded image using
$image = Vips\Image::newFromFile($inputFileName);
Now I want to perform some operations like.
-
Get Exif
- I have used
$image->get('exif-data');But it gives binary data, any thoughts to get it into processeble format (json,xml etc), So I can store those data and use it (GPS Details, Camera Model, Camera name, Orientation Information etc..)
- I have used
-
Resize and Crop operations
- Not able to find how to do this using PHP Library
Almost all methods have options, but I could not able to get syntax of operations or format , I can pass it into it, any detailed documentation for PHP Library ?
Did you see the docs?
https://libvips.github.io/php-vips/docs/classes/Jcupitt.Vips.Image.html
For example:
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
use Jcupitt\Vips;
$image = Vips\Image::newFromFile($argv[1], ['access' => 'sequential']);
echo "SensingMethod = " . $image->get("exif-ifd2-SensingMethod") . "\n";
$image = $image->crop(10, 10, 100, 100);
$image = $image->resize(0.5);
$image->writeToFile($argv[2]);
# it's much faster to open and resize in one step, if you can
$image = Vips\Image::thumbnail($argv[1], 200);
$image->writeToFile($argv[3]);
Run with:
$ ./try311.php ~/pics/Gugg_coloured.jpg x.jpg y.jpg
SensingMethod = 2 (One-chip color area sensor, Short, 1 components, 2 bytes)
exif
Thanks for quick response, any way to get all exif data at once in human readable format? How to get image orientation from exif?
I have tried same sample code as above it throws an exception
[Jcupitt\Vips\Exception, 0]
vips_image_get: field "exif-ifd2-SensingMethod" not found
Your JPEG probably doesn't have this field -- not all cameras provide it.
You can get orientation in the same way.
echo "orientation = " . $image->get("orientation") . "\n";
You can see all fields with:
$ vipsheader -a thing.jpg
You can see all fields with:
$ vipsheader -a thing.jpg
This does not give exif data in human readable format, any way to get all exif data at once in human readable format using php library?
autorot() method have no impact on image, how can I auto rotate uploaded image to TopLeft orientation ?

$image = Vips\Image::newFromFile($inputFileName); $image = $image->autorot(); $image->writeToFile($outputFileName);
Above attached image have Orientation: BottomRight, after autorotate it is same Orientation: BottomRight, can you help me?
Also I tried to get orientation, but no success!
echo "orientation : ". $image->get("orientation");
[Jcupitt\Vips\Exception, 0]
vips_image_get: field "orientation" not found
I am using image having orientation information, Am I missing something?
Perhaps your libvips is missing EXIF support? You'll need libexif-dev at compile time.
Perhaps your libvips is missing EXIF support? You'll need
libexif-devat compile time.
But,
$data = $image->get("exif-data");
is giving response in binary format, is it possible to get that if exif support is not there?
It is something like, can you please help me?

libvips is able to extract the EXIF data block from the JPG file, but it needs libexif to parse it. Where did you get the libvips binary from?
From : https://github.com/libvips/libvips/releases
Hi Recompiled it , now it is working. Getting image information "orientation" doesn't throws an exception and also auto rotation is working.
Thanks
That issue is solved!, Just I want to know one more thing is How to "Get all exif data at once in human readable format" using PHP Library