PHP - new Imagick modifies md5 () images

I am working on an image downloader which should check the md5 images to prevent duplicate images from loading. When the image loads, I create a new Imagick using the loaded path and get the contents of the image. Calling md5 () and passing the contents of the image returns a different value from PHP md5_file and md5sum from the command line. Md5 is stored on the design image object in the database because I need to compare the md5 of the loaded image with existing images. The problem is calling md5 in the new Imagick content, which returns a different value each time the same image is loaded.

$sUploadedImage = '/home/user/test-12x14.png';

md5(file_get_contents($sUploadedImage));
returns  2352513cde38cfb678cf46b6421f2f8b

md5_file($sUploadedImage);
returns  2352513cde38cfb678cf46b6421f2f8b

// md5sum on Linux 
md5sum /home/user/test-12x14.png 
returns 2352513cde38cfb678cf46b6421f2f8b 

$oImagick = new Imagick($sUploadedImage);
md5($oImagick->getImageBlob());
returns 0a8acb080aedf6245b56d39fb705705f
//returns different value on everytime same image is uploaded

$sNewPath = sfConfig::get('sf_root_dir') . '/design-images/' .$sMd5 .'.png';
$oNewImage->writeFileWithFormat($sNewPath, 'png');

md5(file_get_contents($sNewPath));
returns  2352513cde38cfb678cf46b6421f2f8b

md5_file($sNewPath);
returns  2352513cde38cfb678cf46b6421f2f8b

Why is the result of md5 () different on Imagick? Thanks in advance.

+4
1

, PNG , . ImageMagick , , md5sum, , .

. , :

convert -size 256x256 gradient:red-yellow a.png
convert -size 256x256 gradient:red-yellow b.png

md5sum, :

md5 [ab].png
MD5 (a.png) = fbd2be1c89edad043b1d128aaf32a042
MD5 (b.png) = ab08909a80d347d573f5f0f68b2b342e

, , :

identify -format "%#\n" [ab].png
47d48b4144f35ca431e7db577a2b6284ef90649c30ffe9c0b9234aa282297c61
47d48b4144f35ca431e7db577a2b6284ef90649c30ffe9c0b9234aa282297c61

PHP , , Imagick::getImageSignature(void)

+3

Source: https://habr.com/ru/post/1667068/


All Articles