2

I'm currently dealing with a large number of images (over 3000), and I have two copies of each; one large, one small. The problem is I don't have any kind of link to say which small image maps to which large image.

I know roughly which large image goes to which small image (I have an array which contains up to 5 possibilities for each small image), and I'd like to loop round the array and compare each large image to the small image, to see if it's the same image but resized.

TLDR/Didn't Understand: Is there any easy way in PHP to compare two image that are the same, one being (say) 200x200 and the other being (say) 500x500, and determine if they're an image of the same thing?

Joe
  • 15,669
  • 4
  • 48
  • 83

7 Answers7

3

The easiest way would be resize both to a small size (16x16 or 32x32 for example depending on how much CPU you want to use keeping track of the names of each file throughout the process.

Then use imagecolorat() to compare pixel colours through each row/column. You can then define a percentage of which need to match to be considered the same picture.

Edit: here's an example of this implemented http://www.thismayhem.com/php/comparing-images-with-php-gd/

Ben Swinburne
  • 25,669
  • 10
  • 69
  • 108
  • Fantastic. I used this as a base, had to make a few tweaks but you gave me exactly what I was looking for; a starting point :) Thanks a lot. – Joe Oct 21 '11 at 12:43
  • Why don't you just recreate the small images as I suggested in my answer? – middus Oct 21 '11 at 14:12
1

I would use the imagemagick library for resize and compare the images. I would call it using exec()

First, resize the large image using the convert command http://www.imagemagick.org/script/convert.php

Then, compare the small image with the resized image using compare command http://www.imagemagick.org/script/compare.php

vicentazo
  • 1,739
  • 15
  • 19
1

Have you tried if resizing 1 of the big image creates the exact same image as one of the smaller ones(manually use Md5 to find that out).

If it does, then your solution is to batch resize the bigger images to a tmp file and md5 it building an array of bigimagemd5s and then you md5 the smaller ones.

This method will only work if the small images were generated using the php GD algorithm and you have the same compression level and size that was used before.

Mathieu Dumoulin
  • 12,126
  • 7
  • 43
  • 71
  • 1
    Even if I did, the large image scaled down would have a different MD5 due to the scaling algorithm. Unfortunately, not an option. – Joe Oct 21 '11 at 11:55
  • Thats what i said, no need to remove points, it's a solution and it's well written in the solution that it could not work, thanks – Mathieu Dumoulin Oct 21 '11 at 13:19
1

A thing you could do is, take the big picture, scale it to the size of the small picture and check some random pixel-areas there. If the pictures are really different, you could use something like a avg. colour of both images.

But this way is really performance sucking...

Keenora Fluffball
  • 1,647
  • 2
  • 18
  • 34
1

No, there is not a same_image_but_in_different_sizes() function that returns true or false.

If I were you, I'd either sort them manually or choose a color histogram based approach.

I just saw that all "images are JPGs, and they're saved in two folders; large and small". Why don't you just throw small away and recreate it, but this time you remember which belongs to which?

middus
  • 9,103
  • 1
  • 31
  • 33
0

to sort them manually will take you much, much less time.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
0

Please check this link: Compare 2 images in php

It seems that using ImageMagick extension is your best bet, although you'd probably have to scale down the larger image to the same size as your smaller one first.

Community
  • 1
  • 1
thorne51
  • 588
  • 7
  • 23