How to get information from inside the image in PHP?

6

I need to get the information inside the image with PHP, information like: Tags (or tag), Title, Comments, Authors and Copyright .

Does anyone know how to get this information using PHP?

    
asked by anonymous 13.05.2016 / 15:42

1 answer

3

Use the function exif_read_data

  

The exif_read_data() function reads EXIF headers from a JPEG or TIFF image file. Returns an associative array where indexes are the names of headers and values are the values associated with these headers. If no data can be returned, then the result is FALSE.

To enable it on your% s of% remove php.ini from the line:

  • If it is PHP 7.2 (windows, mac osx, linux):

    ;extension=exif
    
  • If Windows and the version is older than PHP 7.2:

    ;extension=php_exif.dll
    
  • If Linux / Mac OSX is older than PHP 7.2:

    ;extension=exif.so
    

After removing ; , getting only:

extension=exif

or

extension=php_exif.dll

or

extension=exif.so

Restart the server, Apache, Nginx, etc.

  

Note that in Windows it is necessary to enable mbstring as well, so in PHP 7.2:

extension=mbstring
     

In earlier versions of PHP:

extension=php_mbstring.dll

Sample usage code:

$exif = exif_read_data('tests/test1.jpg', 'IFD0');

$exif = exif_read_data('tests/test2.jpg', 0, true);

foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
        echo "$key.$name: $val<br />\n";
    }
}

Note that in PHP 7.2 support was added to the following EXIF formats:

  • Samsung
  • DJI
  • Panasonic
  • Sony
  • Pentax
  • Minolta
  • Sigma / Foveon
  • AGFA
  • Kyocera
  • Ricoh
  • Epson

Reference: link

    
16.05.2016 / 22:10