i'm having trouble with a script i modified, i used this class https://github.com/thenakos/compare-images since i wanted to check if in a determined folder there were only uniques photos.
public function scanDir($d)
{
/*function to find same photos in a dir*/
$tabImg = array();
$bitsList = array();
if(is_dir($d))
{
$dir = opendir($d);
$i = 0;
while($file = readdir($dir))
{
$path_parts = pathinfo($file);
if($file != '.' && $file != '..' && isset($path_parts['extension']) && $path_parts['extension'] == 'jpg')
{
$tabImg[] = $file;
$i++;
}
}
}
$i=0;
foreach($tabImg as $keyA => $imgA)
{
if($i<700) {
if(file_exists($d.$imgA))
{
$i1 = $this->createImage($d.$imgA);
if(!$i1){return false;}
$i1 = $this->resizeImage($i1,$d.$imgA);
imagefilter($i1, IMG_FILTER_GRAYSCALE);
$colorMean1 = $this->colorMeanValue($i1);
$bits1 = $this->bits($colorMean1);
$bitsList[$keyA] = $bits1;
imagedestroy($i1);
$i++;
}
}
}
$bitsListToCompare = $bitsList;
foreach($bitsList as $keyList => $valueList)
{
foreach($bitsListToCompare as $keyListToCompare => $valueListToCompare)
{
if($keyList != $keyListToCompare)
{
$hammeringDistance = 0;
for($b = 0;$b<64;$b++)
{
if($valueList[$b] != $valueListToCompare[$b])
{
$hammeringDistance++;
}
}
if($hammeringDistance < 5)
{
if(isset($arraySame[$tabImg[$keyList]])) $arraySame[$tabImg[$keyList]] = $arraySame[$a[$keyList]].';'.$tabImg[$keyListToCompare]; else $arraySame[$tabImg[$keyList]] = $tabImg[$keyListToCompare];
}
}
}
unset($bitsListToCompare[$keyList]);
}
return $arraySame;
}
i've added this function wich basically returns an array of duplicates images. This way it works fine, i'm checking 700 images. But if i don't limit the number of photos to check, i'm getting an error.
Warning: getimagesize() [function.getimagesize]: Read error!
This error is about the following function ( getimagesize )
private function mimeType($i)
{
/*returns array with mime type and if its jpg or png. Returns false if it isn't jpg or png*/
$mime = getimagesize($i);
$return = array($mime[0],$mime[1]);
switch ($mime['mime'])
{
case 'image/jpeg':
$return[] = 'jpg';
return $return;
case 'image/png':
$return[] = 'png';
return $return;
default:
return false;
}
}
i think it's something about the memory but i don't know how to make it work !
Thanks