-2

Using PHP, how can I check whether an image exists within another?

Example:

How can I check whether subimage.jpg exists within mainimage.jpg, using PHP?

  1. subimage.jpg

    subimage.jpg

  2. mainimage.jpg

    mainimage.jpg

Andrew Myers
  • 2,754
  • 5
  • 32
  • 40
Manish Patolia
  • 507
  • 5
  • 23
  • This looks more like a joke, since actually the subimage doesn't even appear in the mainimage. Now if you mean an object (=>bottle) appears in the mainimage, that's a completely different story. – Christian May 13 '23 at 18:40

2 Answers2

1

The Imagick class , Check this link

Using Imagick::compareImages() to Compare images and display the reconstructed image .

<?php

$image1 = new imagick("image1.png");
$image2 = new imagick("image2.png");

$result = $image1->compareImages($image2, Imagick::METRIC_MEANSQUAREERROR);
$result[0]->setImageFormat("png");

header("Content-Type: image/png");
echo $result[0];

?>
Med Dhiia
  • 64
  • 4
  • This makes **no** allowance for shifts, rotations, or most importantly **differences in scale** so it has no chance of working with the supplied images. – Mark Setchell Apr 25 '17 at 14:13
  • @Mark Setchell Be aware OP edited his question heavily after I flagged it as a duplicate – mayersdesign Apr 27 '17 at 13:41
-1

Try this

$img1 = md5(file_get_contents($img1));
$img2 = md5(file_get_contents($img2));

And compare both

Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33