G
G
grabbee2017-02-17 09:38:25
symfony
grabbee, 2017-02-17 09:38:25

Is it possible to find duplicate images in Symfony?

Have you come across a library/bundle to accomplish such a task? Find similar images in the database when uploading a file. Probably hash lookup or something else?..

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Skobkin, 2017-02-17
@skobkin

https://github.com/jenssegers/imagehash

R
Roman Mirilaczvili, 2017-02-17
@2ord

Take a library to get the hash of an image using the pHash algorithm or similar (you need to experiment with the sensitivity threshold), as for example Aleksey Skobkin gave a link .
1. Fill in the phash column with the hash values ​​of all available images.
2. When uploading to the server, having received the hash from the image, check it against the database like:

SELECT id FROM images WHERE HammingDistance(images.phash, uploaded_phash) < 8
LIMIT 1

If there is at least 1 result, then this image is a duplicate.
Implementations of the HammingDistance function may vary depending on the DBMS.

U
usr58, 2017-02-24
@usr58

search for complete duplicates.
if not too lazy to figure it out, then there is what you need:
https://github.com/akeneo/pim-community-dev/tree/m...
https://github.com/akeneo/pim-community-dev/tree/ m...
with each file, its hash is added $sha1 = sha1_file($rawFile->getPathname());
you can search the repository by hashes:
$newFile = new \SplFileInfo('path\to\file.jpg');
$hash = sha1_file($newFile->getPathname());
$repositoryFileInfo = $this->getContainer()->get('akeneo_file_storage.repository.file_info');
$savedFile = $repositoryFileInfo->findOneBy(['hash' => $hash]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question