Coder Social home page Coder Social logo

imagehash's People

Contributors

aliveshiro avatar artyuum avatar bogdanstoik avatar danog avatar grahamcampbell avatar ivqonsanada avatar jenssegers avatar klermonte avatar lstrojny avatar mallardduck avatar mcuelenaere avatar peter279k avatar samwilson avatar winkelement avatar wouterds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imagehash's Issues

MySQL DB data type field to store hash for comparision?

$hasher = new ImageHash();
$hash = $hasher->hash('test.jpg');

... returns hash in HEX-Format like "3c3e0e1a3a1e1e1e".
tried to convert it: $hash->toBin(), but I'll get fatal error.

Do I have to store the returend hash in the format like in the example (Image 1 hash: 3c3e0e1a3a1e1e1e ), or do I have to convert it to binary format (0011110000111110000011100001101000111010000111100001111000011110)?

Which data type to use for the column to store it in a mysql database for comparision ... varchar(), int()

If I save the hashes in HEX ("3c3e0e1a3a1e1e1e") and try to get the hamming distance, results seems not to be correct.

Results from DB ...
SELECT images.*, BIT_COUNT(hash ^ :hash) as hamming_distance
FROM images
HAVING hamming_distance < 5

... are significantly different from ...
$hasher = new ImageHash(new DifferenceHash());
$distance = $hasher->distance($hash3, $hash4);

Hash size

could you add option to change default 64bit hash size ?

Storing Hash metadata along the hashes to enable forward-compatibility & rehashing

Hi,
First of all, thanks for your recent activity, you're upgrading this so fast !

I was thinking that maybe an implementation akin to php's password_hash, password_verify, password_needs_rehash for perceptual hashes would be great.

Maybe you'll want, in x years, to migrate to 128*128 sources for the hashes, or to 256bit hashes, as hardware gains in processing power.. Or you'd like to compensate for switching from an image processing backend to another, and anticipate slightly different hashes.

Maybe along hashes could be stored backend type, sample size, and hash length information, to allow for smarter compare functions ?

The main use case would be something along those lines :

  • Given a picture, hashed on 2017/01/01, with gd, a 32x32 source, to a 64bit hash
  • Given you now hash with imagemagick, a 128x128 source, to a 256bit hash because you found it provides stellar results - this is pure speculation -
  • Given you trigger a massive search for potential duplicates in your database

While walking the database, each hash is compared to today's default implementation. If its hash is obsolete, you can re-hash it instantly and move on with your comparisons.

I'd be willing to work on this if it seems useful enough.
The drawbacks resides in a nonstandard perceptual hash storage, but I doubt there are standards on this matter right now.

Have a nice day !

Undocumented breaking change due to type hints

We're updating to latest version and have noticed a breaking change when using:

Hash::fromInt($num);

This use to allow strings, nulls and even super large integers - but now it seems restricted to int type due to this commit:

v0.6.0...v0.7.0

PHP int value is limited in size, so when we try to use it from values using BIGINT from mysql it no longer works - mysql will return BIGINT values as strings in PHP because they cannot be used as native ints. That's the whole purpose of the BIGINT library, right?

E.g. this is a BIGINT of a difference hash for one of our pictures in our database and it doesn't fit as an int.

echo (int)'10957988095268482955'

fromInt shouldn't typehint int because it's whole purpose is to support big ints.

Crop solid background colours (e.g. black or white borders)

At the moment there doesn't appear to be any way to hook into imagehash to remove solid colours from the image - this causes two images with a heavy black border to look similar.

It would be great if there was a way to filter the image before the perceptual hash is generated.

Take for example these two images - notice the black border on either side. This causes the two images to look 76% similar simply due to the black borders.

7tjPlVMsX5WlUhO4yG3t9uJ9and

7tjPlVMsX5WlUhO4yGgergre3tf

GD provides a imagecropauto which I believe will auto crop out the black / white borders, maybe this could be used?

class not found error

Please help.I run in local this package but i getting Fatal error: Class 'Jenssegers\ImageHash\Implementations\DifferenceHash' not found in /opt/lampp/htdocs/demo/imagehash-master/src/ImageHash.php on line 26

why I getting this error ?Please give answer.

PHPUnit Tests Are Failing

I wanted to try to submit a PR but I gave up because the tests are failing. Please fix?

  1. ImplementationTest::testEqualHashes with data set #5 (Jenssegers\ImageHash\Implementations\BlockHash Object (...))
    Undefined offset: 8

  2. ImplementationTest::testDifferentHashes with data set #5 (Jenssegers\ImageHash\Implementations\BlockHash Object (...))
    Undefined offset: 8

use__

how do i use the following code in implimentation??

Not everyone have gd

PHP Fatal error:  Uncaught Error: Call to undefined function Jenssegers\ImageHash\imagecreatefromstring() in /home/vganzin/_/ebay/vendor/jenssegers/imagehash/src/ImageHash.php:126
Stack trace:
#0 /home/vganzin/_/ebay/vendor/jenssegers/imagehash/src/ImageHash.php(49): Jenssegers\ImageHash\ImageHash->loadImageResource('./forest-high.j...')
#1 /home/vganzin/_/ebay/imagehash.php(6): Jenssegers\ImageHash\ImageHash->hash('./forest-high.j...')
#2 {main}
  thrown in /home/vganzin/_/ebay/vendor/jenssegers/imagehash/src/ImageHash.php on line 126

PHP 7
Archlinux

ImageHash does not work on remote directories in macOS Catalina

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

installation errors at UBUNTU 16

on composer require jenssegers/imagehash the first problem, that need some FAQ was

file_put_contents(/home/peter/.composer/cache/repo/https---packagist.org/p-provider-2016-10.json): failed to open stream: Permission denied
http://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date

Them, suppose fix by (not recommended) sudo ... Ok, no permission error, but a new error:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for jenssegers/imagehash dev-master -> satisfiable by jenssegers/imagehash[dev-master].
    - Can only install one of: jenssegers/imagehash[v0.4.1, dev-master].
    - Installation request for jenssegers/imagehash ^0.4.1 -> satisfiable by jenssegers/imagehash[v0.4.1].


Installation failed, reverting ./composer.json to its original content.

License

Hi,
i wanted to use your code to write a plugin for the resourcespace open source digital asset management but as i can't find any license information about the usage of your code so i'm asking what are the conditions of use?

Thanks and best regards!

Round up the hash value

Hello,

Great class you created and great job done.
As for sure you already studied the question, maybe you can suggest the best way to accomplish the following:

I need to find a duplicates of images in the database and it is not really good idea to compare 2 images one by one...so I came up with the idea - basically what I want to do is to round a Hash result a little and store it for each image in DB...and later just find duplicated values of Hash. I do understand that the result of this solution will not be comparable to the result I get when calculating the hamming distance, but it is ok for me - I just need to find images that are with 95+% probability are duplicated...
So, the question is - what is the best place of code to round the Hash? I tried to do it in ImageHash.php, but something goes wrong:

$hash = round($hash/10)*10;
return $hash;

returns some stupid results like 9.23423423423E+34

Any idea what am I doing wrong?

Thank you in advance!!!

Hash size

Fabulous work, thanks.

I see the examples have different hash lenght. Is the hash length corresponds to the image dimensions? I believe the hash represents the image details. Can we specify the sensitivity (for example with changing the hash length to 512 byte)?

Thanks.

Archive this repo

It seems that this repo has no activity. I suggest to archive this.

Too many collisions?

Maybe I am doing it wrong but I ran through about 1,250 images (out of more than 350,000) and hashed (Perceptual) them. I then stored the hash in the database and I am using the SQL Bit_COUNT to get the hamming distance.

I took a random hash and ran the query and ended up with 2 at a distance of 0 (different hashes) and maybe 50 or more at a distance of 1. The farthest away is a distance of 27.

These are the two images that had different hashes but yet were still 0 away.

Hash: 12d2552c66ddc94b (image: https://10deb7fbfece20ff53da-95da5b03499e7e5b086c55c243f676a1.ssl.cf1.rackcdn.com/a1afc58c6ca9540d057299ec3016d726_l.jpg)

Hash: 12e627593dbc2307 (image: https://10deb7fbfece20ff53da-95da5b03499e7e5b086c55c243f676a1.ssl.cf1.rackcdn.com/3b8a614226a953a8cd9526fca6fe9ba5_l.jpg)

As you can see these are not anywhere close to the same.

SELECT c.*, BIT_COUNT('12e627593dbc2307' ^ i.hash) as hamming_distance
FROM images i
where hash is not null
ORDER BY hamming_distance ASC

Will this not work on "created" images? Maybe the sample size is too small for an accurate comparison. I think I am reading it is converted to an 8x8 image...maybe in my case it should be MUCH larger but I am not sure where to start.

Same result for different images

I really like this library. But I need some improvement. Like in this example. The hash is the same, but the images are different. I need more accuracy and certainty that the pictures are the same.

How to do it?
Snímek obrazovky 2022-06-26 v 15 18 32

Comparing with all existing hashes in DB

Hi! It is works fine if I need to compare exactly two images. But what if I have 3 millions hashes in DB and need to compare my current hash with each other in database (find all similar from images that already exists). Is there any solution except direct comparing? May be it's possible to use something similar to distance function right in database?

Differences using ImageHash Class and MySQL DB comparision

I've got three test images ..
ImageHash gives following hashes ..

Image 1: 0405794952704d4a
Image 2: 0405714972704d48
Image 3: 0445714972704d4a

Distances in ImageHash are always 3 using example:

use Jenssegers\ImageHash\ImageHash;
use Jenssegers\ImageHash\Implementations\DifferenceHash ;

$hasher = new ImageHash(new DifferenceHash());
$distance = $hasher->distance($hash1, $hash2); // = 3
$distance = $hasher->distance($hash1, $hash3); // = 3

If the hashes are inserted into MySQL DB in column "hash" ( data type varchar() ) ...

SELECT images.*, BIT_COUNT('0405794952704d4a' ^ hash) as hamming_distance
FROM images
HAVING hamming_distance < 50

Distances are as followed ..

Image 1: 0405794952704d4a -> 0
Image 2: 0405714972704d48 -> 12
Image 3: 0445714972704d4a -> 21

I am expecting hamming distance of 3 like using the ImageHash DifferenceHash() Class.
Where is my fault?

Adapter for GD / no image intervention (performance improvement)

Is there any interest in having a faster adapter which just uses PHP GD to process images rather than going through Intervention package? On my machine using simple gd operations such as imagecolorsforindex and imagecolorat to get colours is around double the speed as using Intervention (I assume because that has a lot of overhead under the hood for validating arguments, creating lots of objects, garbage collection, etc)

As a side note - maybe the intervention package could be an optional inclusion (if you want to support Imagemagick) but by default this library could focus on gd support only out the box? Pulling in intervention for some basic image calculations probably isn't necessary.

Unable to init from given binary data to 80.jpg

Hi.
I am developing on Laravel 5.5 project using laradock.

When outputting image file names sequentially, an error is output for a specific image.
The content of the error is "Unable to init from given binary data."
But, hashing a specific image will cause an error.

80.jpg
80_image.jpg
801 ... 809.jpg
801 ... 809_image.jpg

In this way, if the prefix is ​​"80" an error will be output.
This phenomenon occurs when outputting images in sequential order.

At present, it is solved by attaching "image_" to the prefix, but I think that it is not the root solution.

If you look at the contents of the error, It is an error in
"/vendor/intervention/image/src/Intervention/Image/Gd/Decoder.php"

Decoder.php Error Message

     * Initiates new image from binary data
     *
     * @param  string $data
     * @return \Intervention\Image\Image
     */
    public function initFromBinary($binary)
    {
        $resource = @imagecreatefromstring($binary);
    if ($resource === false) { <--- $resource is false so true
         throw new \Intervention\Image\Exception\NotReadableException(
            "Unable to init from given binary data."
        );
    }

    $image = $this->initFromGdResource($resource);
    $image->mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary);

    return $image;
}

It is an error of the library used by imagehash, so it may not be the contents to ask here.
Please pardon.

Laravel Error Message

#60 Intervention\Image\Exception\NotReadableException in /var/www/my-project/vendor/intervention/image/src/Intervention/Image/Gd/Decoder.php:113
#59 Intervention\Image\Gd\Decoder:initFromBinary in /var/www/my-project/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php:326
#58 Intervention\Image\AbstractDecoder:init in /var/www/my-project/vendor/intervention/image/src/Intervention/Image/AbstractDriver.php:64
#57 Intervention\Image\AbstractDriver:init in /var/www/my-project/vendor/intervention/image/src/Intervention/Image/ImageManager.php:52
#56 Intervention\Image\ImageManager:make in /var/www/my-project/vendor/jenssegers/imagehash/src/ImageHash.php:40
#55 Jenssegers\ImageHash\ImageHash:hash in /var/www/my-project/app/Http/UseCases/EncodeUseCaseImpl.php:27
#54 App\Http\UseCases\EncodeUseCaseImpl:encodeDifferenceHash in /var/www/my-project/app/Http/Controllers/HomeController.php:145
#53 App\Http\Controllers\HomeController:upload in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
#52 call_user_func_array in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
#51 Illuminate\Routing\Controller:callAction in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45
#50 Illuminate\Routing\ControllerDispatcher:dispatch in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Route.php:212
#49 Illuminate\Routing\Route:runController in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Route.php:169
#48 Illuminate\Routing\Route:run in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:658
#47 Illuminate\Routing\Router:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#46 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
#45 Illuminate\Routing\Middleware\SubstituteBindings:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#44 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#43 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:68
#42 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#41 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#40 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
#39 Illuminate\View\Middleware\ShareErrorsFromSession:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#38 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#37 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:63
#36 Illuminate\Session\Middleware\StartSession:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#35 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#34 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
#33 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#32 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#31 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:66
#30 Illuminate\Cookie\Middleware\EncryptCookies:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#29 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#28 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
#27 Illuminate\Pipeline\Pipeline:then in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:660
#26 Illuminate\Routing\Router:runRouteWithinStack in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:635
#25 Illuminate\Routing\Router:runRoute in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:601
#24 Illuminate\Routing\Router:dispatchToRoute in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:590
#23 Illuminate\Routing\Router:dispatch in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
#22 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#21 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php:65
#20 Barryvdh\Debugbar\Middleware\InjectDebugbar:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#19 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#18 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/fideloper/proxy/src/TrustProxies.php:56
#17 Fideloper\Proxy\TrustProxies:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#15 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
#14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#12 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
#11 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#9 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
#8 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#6 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:46
#5 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#3 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
#2 Illuminate\Pipeline\Pipeline:then in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /var/www/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
#0 Illuminate\Foundation\Http\Kernel:handle in /var/www/my-project/public/index.php:55

use source

<?php

namespace App\Http\UseCases;

use File;
use FFMpeg;
use Storage;
use Jenssegers\ImageHash\ImageHash;
use Jenssegers\ImageHash\Implementations\DifferenceHash;

class EncodeUseCaseImpl implements EncodeUseCase
{
    public function encodeDifferenceHash(array $getImageList) : array
        {
            $hasher = new ImageHash(new DifferenceHash());
            $count = \count($getImageList);
            for ($num = 0; $num < $count; ++$num) {
                $hash[] = $hasher->hash($getImageList[$num])->toHex();
            //error image data 80_image.jpg or 800_image.jpg or 801...809_image.jpg
            }
            return $hash;
        }
...
}

My development environment supported jpeg on GD

SnapCrab_NoName_2019-5-14_21-8-8_No-00

Why returns hex hash in last version?

In previous version method ImageHash->hash() returns an integer? Now it hex value in type "string". I have database of hashes in BIGINT type, and search in integer field is faster than string.

Not always returning a 16 char hash

I sometimes get 15 char hashes and very occasionally 14 chars.
My suspicion is that the first chars of the binary are being lost if they are 0 as it looks like an integer to php. Any thoughts on what I might be missing?

BlockHash

Thanks for the hard work on this!

Is anyone working on fixing Blockhash? I had a look and compared to the JS implementation, but honestly I'm not sure why it's trying to access the 17th array element.

It'd be good to be able to compare Blockhash vs the others. So far PerceptualHash seems the best to me.

Uncaught Error: Call to a member function toHex()

include('vendor/autoload.php');

use Jenssegers\ImageHash\ImageHash;
use Jenssegers\ImageHash\Implementations\DifferenceHash;

$hasher = new ImageHash(new DifferenceHash());
$hash = $hasher->hash('img/forest-copyright.jpg');

echo $hash->toHex();` <----- Fatal error: Uncaught Error: Call to a member function toHex() on string ...

Why?

Switch `phpseclib\Math\BigInteger To Something Lighter

This composer module pulls phplibsec to use phpseclib\Math\BigInteger

use phpseclib\Math\BigInteger;

"phpseclib/phpseclib": "^2.0"

In addition to BigInteger, adding phplibsec to your composer.json brings with it Pure-PHP implementations of SSHv1, SSHv2, SFTP, SCP... None of which is used by imagehash.

Please switch to: https://github.com/brick/math

Or maybe, copy paste the code you need into your project? It's one file if you comment out:

https://github.com/phpseclib/phpseclib/blob/c78eb5058d5bb1a183133c36d4ba5b6675dfa099/phpseclib/Math/BigInteger.php#L52

The Crypt\Random class is optional:

https://github.com/phpseclib/phpseclib/blob/c78eb5058d5bb1a183133c36d4ba5b6675dfa099/phpseclib/Math/BigInteger.php#L3099

New maintainers

@jenssegers It seems the last commit was made over 2 years ago. This library is fairly well used and starred and has some outstanding issues with PR requests.

Is there any plans to bring in new maintainers, or should the library be marked as officially abandoned?

It would be great to have some guidance on what your plans, so the community knows whether to fork or not.

image

Fatal error: echo $hash->toBin();

echo $hash->toBin(); produces fatal error ..
Fatal error: Uncaught Error: Call to undefined method Jenssegers\ImageHash\Hash::toBin()

Different values for difference with gmp support

$hasher = new ImageHash;
echo $hasher->distance('821412112525090f','821616112521050f');

Not such a big deal as at least will be consistent on the machine
My mac has no gmp and returns 3. With gmp returns 5

phpseclib/phpseclib version issue was reported when composer introduced the package

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for jenssegers/imagehash ^0.7.0 -> satisfiable by jenssegers/imagehash[v0.7.0].
- Can only install one of: phpseclib/phpseclib[3.0.8, 2.0.8].
- Can only install one of: phpseclib/phpseclib[2.0.8, 3.0.8].
- Can only install one of: phpseclib/phpseclib[2.0.8, 3.0.8].
- Conclusion: install phpseclib/phpseclib 2.0.8
- Installation request for phpseclib/phpseclib (locked at 3.0.8) -> satisfiable by phpseclib/phpseclib[3.0.8].

Installation failed, reverting ./composer.json to its original content.

Format Image

how to compare image with format file .svg ??

Library does not support php 8.0.1

I got this error when trying to use composer for updating

- Root composer.json requires jenssegers/imagehash ^0.7.0 -> satisfiable by

jenssegers/imagehash[v0.7.0].
- jenssegers/imagehash v0.7.0 requires php ^7.0 -> your php version (8.0.1
does not satisfy that requirement.

Hash length question

Hi guys, good work!! i have just one question: what is the resulting length of the hash?
Thanks

question

great library, need to say that first.

Scenario:
If we have a large library of pictures, we can calculate and store the ahash, dhash and phash in an mysql table.
Then, for any new picture, we can calculate the hash, but in order to see if we already have something similar in the db, we need to calculate the distance between the new pic and each of the hashes stored in the db.
Is there any way to translate the comparison function to a mysql function, so that we would "select" the values in the db that are near the hash we are checking?

it breaks for the big images

I am trying to make a laravel package using your repo but it break when the images are big in size eg 10-15 mb.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.