note 109180 added to imagick.getimagesignature
| From: | holdoffhunger at gmail dot com | Date: | Tue, 26 Jun 2012 11:51:10 +0000 |
| Subject: | note 109180 added to imagick.getimagesignature | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188802@lists.php.net to get a copy of this message | ||
The getImageSignature function for the ImageMagick package in PHP returns only the SHA-1 hash value
for an image. There are not any other algorithms available for it within the ImageMagick package,
but fortunately, this is PHP and you have a wide array of hashing algorithms to use on any image
file. The function hash_algos() will return an array of hashing algorithms available in PHP and the
function hash_file() will take three parameters (one for the algorithm to use, one for the filename,
and an optional variable for binary output). Instead of being limited to the SHA-1 algorithm of the
getImageSignature function, you could use SHA-256, SHA-384, SHA-512, Whirlpool, HAVAL, Salsa, Gost,
Adler32, CRC32, or MD5, among others and variations of these.
However, the SHA-1 result of the hash_file() function performed on a file does not return the same
result as the SHA-1 of the getImageSignature() function. This leads me to believe that the SHA-1 of
the getImageSignature() might be performed on the Imagick object itself, instead of the file,
whereas the hash_file() function is clearly performed on the file itself. That's just a guess,
though.
Some sample code for the alternate hashing algorithm, with every algorithm performed on the image
file :
<?php
// Author: holdoffhunger@gmail.com
// Set File for Hashing Function
// ---------------------------------------------------
$filename_with_folder_for_hashing = "image_workshop/test_file.bmp";
// Acquire Dynamic Hashing Algorithm List
// ---------------------------------------------------
$php_dynamic_hash_algorithms = hash_algos();
// Count Dynamic Hashing Algorithm List
// ---------------------------------------------------
$number_of_dynamic_hash_algorithms = count($php_dynamic_hash_algorithms);
// Parse Dynamic Hashing Algorithm List
// ---------------------------------------------------
for($i = 0; $i < $number_of_dynamic_hash_algorithms; $i++)
{
// Get Current Hashing Algorithm
// ---------------------------------------------------
$current_hashing_algorithm = $php_dynamic_hash_algorithms[$i];
// Perform Hashing on File
// ---------------------------------------------------
$current_hashing_algorithm_hex_result = hash_file($current_hashing_algorithm,
$filename_with_folder_for_hashing, FALSE);
// Print Hashed Results
// ---------------------------------------------------
print("$current_hashing_algorithm Algorithm ::: $current_hashing_algorithm_hex_result");
print("<br><br>");
}
?>
Example Results:
...........................
md2 Algorithm ::: 03205df9c6717d74f1f003c66f58e98a
md4 Algorithm ::: b2a204a2e5c3968d2abd5dc372fbee10
md5 Algorithm ::: b9d92a61714b221d24c7730d4764ca82
sha1 Algorithm ::: 8db4c92346c26568b13ea43fbcf514e37942a41a
(and so on for 34 more algorithms)...
----
Server IP: 69.147.83.197
Probable Submitter: 68.9.137.178
----
Manual Page -- http://www.php.net/manual/en/imagick.getimagesignature.php
Edit -- https://master.php.net/note/edit/109180
Del: integrated -- https://master.php.net/note/delete/109180/integrated
Del: useless -- https://master.php.net/note/delete/109180/useless
Del: bad code -- https://master.php.net/note/delete/109180/bad+code
Del: spam -- https://master.php.net/note/delete/109180/spam
Del: non-english -- https://master.php.net/note/delete/109180/non-english
Del: in docs -- https://master.php.net/note/delete/109180/in+docs
Del: other reasons-- https://master.php.net/note/delete/109180
Reject -- https://master.php.net/note/reject/109180
Search -- https://master.php.net/manage/user-notes.php