Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which image formats contain meta data, and how can I clear it in PHP?

Privacy concerns have lead me to believe I should scrub user uploaded images for any meta data.

I know that JPEG have EXIF, but I'm not sure about PNG or GIF (both are able to be uploaded to my site from the public).

Do these formats have meta data too, and how is it stored? What is the best way to remove it?

I'm using PHP 5.29.

Thanks

like image 393
alex Avatar asked Sep 05 '10 08:09

alex


2 Answers

You may try http://www.php.net/manual/en/imagick.stripimage.php

$f = '16262403.jpg';
$i = new Imagick($f);
$p = $i->getImageProperties();
var_dump($p);
array(5) {
  ["comment"]=>
  string(20) "(C) Drom.ru #4495317"
  ["date:create"]=>
  string(25) "2012-05-29T17:15:32+03:00"
  ["date:modify"]=>
  string(25) "2012-05-29T17:15:30+03:00"
  ["jpeg:colorspace"]=>
  string(1) "2"
  ["jpeg:sampling-factor"]=>
  string(11) "2x2,1x1,1x1"
}

$i->stripImage();

$p = $i->getImageProperties();
var_dump($p);
array(2) {
  ["jpeg:colorspace"]=>
  string(1) "2"
  ["jpeg:sampling-factor"]=>
  string(11) "2x2,1x1,1x1"
}
like image 124
uKolka Avatar answered Sep 28 '22 05:09

uKolka


The easiest way is to copy them to a new image with GD - you keep all the image info, but get rid of the metadata.

like image 43
Maerlyn Avatar answered Sep 28 '22 04:09

Maerlyn