php-vips icon indicating copy to clipboard operation
php-vips copied to clipboard

How to get image exif data?

Open rahulthackkar opened this issue 5 years ago • 13 comments

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..)
  • 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 ?

rahulthackkar avatar Jul 31 '20 11:07 rahulthackkar

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)

jcupitt avatar Jul 31 '20 11:07 jcupitt

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?

rahulthackkar avatar Jul 31 '20 12:07 rahulthackkar

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

rahulthackkar avatar Jul 31 '20 12:07 rahulthackkar

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

jcupitt avatar Jul 31 '20 12:07 jcupitt

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 ? testimagewithorientation1

$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?

rahulthackkar avatar Jul 31 '20 12:07 rahulthackkar

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?

rahulthackkar avatar Jul 31 '20 13:07 rahulthackkar

Perhaps your libvips is missing EXIF support? You'll need libexif-dev at compile time.

jcupitt avatar Jul 31 '20 13:07 jcupitt

Perhaps your libvips is missing EXIF support? You'll need libexif-dev at 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?

rahulthackkar avatar Jul 31 '20 13:07 rahulthackkar

It is something like, can you please help me?

Screenshot from 2020-07-31 18-44-41

rahulthackkar avatar Jul 31 '20 13:07 rahulthackkar

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?

jcupitt avatar Jul 31 '20 14:07 jcupitt

From : https://github.com/libvips/libvips/releases

rahulthackkar avatar Jul 31 '20 14:07 rahulthackkar

Hi Recompiled it , now it is working. Getting image information "orientation" doesn't throws an exception and also auto rotation is working.

Thanks

rahulthackkar avatar Jul 31 '20 14:07 rahulthackkar

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

rahulthackkar avatar Jul 31 '20 14:07 rahulthackkar