Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:32:58+00:00 2026-06-14T19:32:58+00:00

I want to compare two images in PHP. If they are 95% or above

  • 0

I want to compare two images in PHP. If they are 95% or above similar then the result should be just displaying text Yes. If they are not similar the result should be No.
So

if ( ) 
{
echo "Yes";
}
else
{
echo "No";
}

Any way this is so far what I had found. http://pastebin.com/wgeu2DqE
I would like to give you where I found it but you would have to register.

Now I have this function to load image

function LoadPNG($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefrompng($imgname);

    /* See if it failed */
    if(!$im)
    {
        /* Create a blank image */
        $im  = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);

        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);

        /* Output an error message */
        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }

    return $im;
}

I’ve been trying on my notepad++ and phpdesigner to come up with something but I get errors. I am not a php developer so I am asking a help from you guys. I just need comparison between two images and Yes or No. So this is pretty easy. I saw this too but couldn’t make sense out of it.

Compare 2 images in php

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:32:59+00:00Added an answer on June 14, 2026 at 7:32 pm

    You can do the compare in several ways, depending on what kind of compare you want and the use case. “Similar” is a very ambiguous term.

    There are image comparing libraries, or you can use the ImageMagick functions. There is even a binding for OpenCV to use with PHP.

    Of course, the more complex the approach, the more flexible and better the results.

    If you are comparing two images that ought to be equal and aren’t (for example, say, two surveillance camera frames), you can use the DIY method given below.

    If there are distortions in hue and luminosity (e.g. noise), then the DIY method will not work, but ImageMagick will give good results.

    Finally if you’re trying to map two views of the same object, e.g. from a camera that panned a foot to the left, or you are looking for an image “inside” another, etc., then OpenCV is the only viable alternative of the three.

    A do-it-yourself approach, for the simplest case, could be to first check the aspect ratio of the two images, then reduce both to the same size (you can reduce them even further (say, scale 1:4) to filter out small differences and/or also reduce the work ahead).

    At that point, you can compare the two images pixel by pixel using getColorAt (and also optionally convert to grayscale to ignore differences in hue). The distance between two pixels can also be calculated in several ways (e.g. with CIE perceptual functions), or you can use the Euclidean distance – SQRT((r1-r2)*2 + (g1-g2)*2 + (b1-b2)**2).

    Distance can range from 0 to W*H*255*SQRT(3); you can map linearly these values to the range 0-100%.

    This can tell you easily the difference between an image, and the same image with some lines drawn on it. If you distort the image (e.g. with a “pinch” filter), or rotate it a little, the resulting image will appear 95%, even 99% identical, and yet this algorithm could well report a very low match (for photo quality pictures, with continuous tones, match will still be good. For cartoons, it will be very poor).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to compare two vector images (say SVG) and see how close they
How can I take two images and compare them to see how similar they
I want to compare two CSV files to see if they are different. I
I want to compare two images using OpenCV. Could I filter the nearest matching
I need to compare two images that are screenshots of a software. I want
I have two images which I want to compare using python and opencv. I
I want to compare the pixel of the two different images. I am comparing
I want to compare two routes to check if they are same or not
In PHP, I want to compare two relative URLs for equality. The catch: URLs
I want to compare two ms-access .mdb files to check that the data they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.