note 47235 modified in ref.image by didou
| From: | didou@php.net | Date: | Mon, 08 Nov 2004 04:08:58 +0000 |
| Subject: | note 47235 modified in ref.image by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80260@lists.php.net to get a copy of this message | ||
A simple image compare function.
It scans 2 images pixel by pixel, from left to right and from top to bottom, if all pixels have
equal colors it will return 'True', otherwise it will return 'False'.
$img1 and $img2 must be of type image. (see usage)
----------------------------------------------
function imagecompare($img1, $img2) {
if (imagesx($img1)!=imagesx($img2) || imagesy($img1)!=imagesy($img2)){
return false;
}
for( $x=0; $x<imagesx($img1 ); $x++ ){
for ($y=0; $y<imagesy($img1); $y++) {
if(imagecolorat($img1,$x,$y)!=imagecolorat($img2,$x,$y)){
return false;
}
}
}
return true;
}
----------------------------------------------
Sample usage:
$im1=imagecreatefromgif("test1.gif");
$im2=imagecreatefromgif("test2.gif");
echo imagecompare(&$im1,&$im2);
--was--
A simple image compare function.
It scans 2 images pixel by pixel, from left to right and from top to bottom, if all pixels have
equal colors it will return 'True', otherwise it will return 'False'.
$img1 and $img2 must be of type image. (see usage)
----------------------------------------------
function imagecompare( &$img1,&$img2 ) {
if (imagesx($img1)!=imagesx($img2) OR imagesy($img1)!=imagesy($img2)){
return False;
break;
}
for( $x=0; $x<imagesx($img1 ); $x++ ){
for ($y=0; $y<imagesy($img1); $y++) {
if(imagecolorat($img1,$x,$y)!=imagecolorat($img2,$x,$y)){
return False;
break;
}
}
}
return True;
break;
}
----------------------------------------------
Sample usage:
$im1=imagecreatefromgif("test1.gif");
$im2=imagecreatefromgif("test2.gif");
echo imagecompare(&$im1,&$im2);
http://php.net/manual/en/ref.image.php