jenssegers / imagehash Goto Github PK
View Code? Open in Web Editor NEW🌄 Perceptual image hashing for PHP
Home Page: https://jenssegers.com
License: MIT License
🌄 Perceptual image hashing for PHP
Home Page: https://jenssegers.com
License: MIT License
$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);
could you add option to change default 64bit hash size ?
我在MacOS上进行程序开发,当部署到centOS服务器上之后,对于相同的PNG图片产生了和macOS上不一致的结果。
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 :
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 !
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:
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.
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.
GD provides a imagecropauto
which I believe will auto crop out the black / white borders, maybe this could be used?
It seems you had another update on the library but didnt updated the documentation..
On using toHex():
PHP Fatal error: Uncaught Error: Call to a member function toHex() on string in..
What is the best method of conversion?
It seems you had another update on the library but didnt updated the documentation..
On using toHex():
PHP Fatal error: Uncaught Error: Call to a member function toHex() on string in..
What is the best method of conversion?
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.
I wanted to try to submit a PR but I gave up because the tests are failing. Please fix?
how do i use the following code in implimentation??
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
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
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.
Would like to ask if imagehash can handle these types of edited images
Goal: Update on https://github.com/pippy360/transformationInvariantImageSearch
Comparison: https://github.com/kennethrapp/phasher
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!
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!!!
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.
Your library are using "Marr/Mexican hat wavelet" algorithm?
It seems that this repo has no activity. I suggest to archive this.
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.
If you hash an image by filename the hash function will create a resource that is never closed.
https://github.com/jenssegers/php-imagehash/blob/master/src/ImageHash.php#L36
public function hash($resource)
{
$resource = is_resource($resource) ? $resource : $this->loadImageResource($resource);
$hash = $this->implementation->hash($resource);
return $hash;
}
are there any plans to add perceptual hashing using imagick instead of GD?
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?
Using $hash->toInt()
in a image, the returned value is float, not integer
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?
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.
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"
* 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.
#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
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.
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?
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.
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?
This composer module pulls phplibsec to use phpseclib\Math\BigInteger
Line 6 in 67cf9d7
Line 19 in 67cf9d7
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:
The Crypt\Random class is optional:
The matrix is 32x32, are the first 8x8 ordered in any relevant way?
Also which hash is performing better for you?
@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.
echo $hash->toBin(); produces fatal error ..
Fatal error: Uncaught Error: Call to undefined method Jenssegers\ImageHash\Hash::toBin()
Seems the composer module is missing the Hash class:
https://raw.githubusercontent.com/jenssegers/imagehash/master/src/Hash.php
$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
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.
how to compare image with format file .svg ??
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.
Hi guys, good work!! i have just one question: what is the resulting length of the hash?
Thanks
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?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.