Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageHash does not work on remote directories in macOS Catalina #64

Open
shivanraptor opened this issue Sep 9, 2020 · 1 comment
Open

Comments

@shivanraptor
Copy link

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

@VincentChalnot
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants