imagehash icon indicating copy to clipboard operation
imagehash copied to clipboard

ImageHash does not work on remote directories in macOS Catalina

Open shivanraptor opened this issue 3 years ago • 1 comments

I am using the following code to obtain the HEX hash:

<?php
header('Content-Type: text/plain');
require_once('vendor/autoload.php');
use Jenssegers\ImageHash\ImageHash;
use Jenssegers\ImageHash\Implementations\DifferenceHash;

function getPhotoDuplicate($hasher, $dir)
{
    $fileList = array();
    $allowedExtensions = ['jpg', 'jpeg'];
    foreach (new DirectoryIterator($dir) as $file) {
        if ($file->isDir() || $file->isDot() || !in_array($file->getExtension(), $allowedExtensions, true)) {
        	continue;
		}
        $path = $file->getFilename();
        echo $path . PHP_EOL; // this is working
        $hash = $hasher->hash($path);
        $fileList[$path] = $hash->toHex();
    }
    return $fileList;
}

$hasher = new ImageHash(new DifferenceHash());
$files = getPhotoDuplicate($hasher, '/Volumes/MyUSB/Some/Folder/Here/'); 
print_r($files);
?>

Actually the code is quite straightforward, which loops through a directory containing a thousand images.

The same code works on local directory (e.g. same directory .), but not on remote USB-connected directory. The same set of images is used. The error is as follow:

PHP Fatal error:  Uncaught Intervention\Image\Exception\NotReadableException: Image source not readable in /Volumes/MyUSB/Some/Folder/Here/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php:346
Stack trace:
#0 /Volumes/MyUSB/Some/Folder/Here/vendor/intervention/image/src/Intervention/Image/AbstractDriver.php(66): Intervention\Image\AbstractDecoder->init('1000202606_1583...')
#1 /Volumes/MyUSB/Some/Folder/Here/vendor/intervention/image/src/Intervention/Image/ImageManager.php(54): Intervention\Image\AbstractDriver->init('1000202606_1583...')
#2 /Volumes/MyUSB/Some/Folder/Here/vendor/jenssegers/imagehash/src/ImageHash.php(35): Intervention\Image\ImageManager->make('1000202606_1583...')
#3 /Volumes/MyUSB/Some/Folder/Here/photo_duplicate.php(17): Jenssegers\ImageHash\ImageHash->hash('1000202606_1583...')
#4 /Volumes/MyUSB/Some/Folder/Here/photo_duplicate.php(24): getPhotoDuplicate(Object(Jenssegers\ImageHash\ImageHash), '/Volumes/MyUSB...')
#5 {main}
  thrown in /Volumes/MyUSB/Some/Folder/Here/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php on line 346

Fatal error: Uncaught Intervention\Image\Exception\NotReadableException: Image source not readable in /Volumes/MyUSB/Some/Folder/Here/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php:346
Stack trace:
#0 /Volumes/MyUSB/Some/Folder/Here/vendor/intervention/image/src/Intervention/Image/AbstractDriver.php(66): Intervention\Image\AbstractDecoder->init('1000202606_1583...')
#1 /Volumes/MyUSB/Some/Folder/Here/vendor/intervention/image/src/Intervention/Image/ImageManager.php(54): Intervention\Image\AbstractDriver->init('1000202606_1583...')
#2 /Volumes/MyUSB/Some/Folder/Here/vendor/jenssegers/imagehash/src/ImageHash.php(35): Intervention\Image\ImageManager->make('1000202606_1583...')
#3 /Volumes/MyUSB/Some/Folder/Here/photo_duplicate.php(17): Jenssegers\ImageHash\ImageHash->hash('1000202606_1583...')
#4 /Volumes/MyUSB/Some/Folder/Here/photo_duplicate.php(24): getPhotoDuplicate(Object(Jenssegers\ImageHash\ImageHash), '/Volumes/MyUSB...')
#5 {main}
  thrown in /Volumes/MyUSB/Some/Folder/Here/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php on line 346

Is this a bug? or did I miss something?

Using PHP 7.4.10, GMP 6.2.0 on macOS Catalina 10.15.6

shivanraptor avatar Sep 09 '20 06:09 shivanraptor

I don't think this has anything to do with this library, try to fopen the image you will probably see the same error.

VincentChalnot avatar Nov 22 '20 10:11 VincentChalnot