Page 1 of 1
Compare two images
Posted: Thu Aug 17, 2006 10:04 pm
by Light
Hi all,
Could someone help me? I want to know if I can compare two images pixel by pixel by using php.
Thank you
Posted: Thu Aug 17, 2006 10:06 pm
by feyd
You can. It's not fun, but you can.
Posted: Fri Aug 18, 2006 9:48 am
by JayBird
What exactly do you want to achieve? Do you want to see if two images are the same or what?
Posted: Fri Aug 18, 2006 5:55 pm
by Light
JayBird,
Yes, I want to see if two images are the same.
==================================
feyd,
Thank you.
Posted: Fri Aug 18, 2006 6:44 pm
by nickvd
Not tested, probably wont work:
Code: Select all
if (md5_file($image1) == md5_file($image2)) {
//images are equal
} else {
//images are not equal
}
Edit thanks to AC
Posted: Fri Aug 18, 2006 7:58 pm
by Ambush Commander
That's what I'd do, except I'd use
md5_file() to avoid loading the images into memory.

Posted: Fri Aug 18, 2006 8:10 pm
by nickvd

Ya learn something new every day... didn't know that function existed... I'll edit my post
Tnx AC!!!
Posted: Fri Aug 18, 2006 10:32 pm
by feyd
Compare
filesize() first, if you're going to run that. If they're different sizes, what's the point of running
md5()?

Posted: Fri Aug 18, 2006 11:35 pm
by Light
Thank you,
Actually, I want to know the code to put it in my forum. When vistors register in my forum, they enter their image like password. Their image will be in the database. If they want to use my forum, they should enter their image after that the code will compare two images.
Is ti possible?
Again, thank you
Posted: Fri Aug 18, 2006 11:39 pm
by feyd
They're using an image as or in place of a password? Or do you mean a
Captcha?
Posted: Sat Aug 19, 2006 12:00 am
by Light
Hi,
They will use an image in place of a password.
Thank you
Posted: Sat Aug 19, 2006 12:06 am
by feyd
A little strange, but okay... I'd suggest the
SHA256 library then. If you don't understand it, I would suggest
sha1()/
sha1_file() over
md5()/
md5_file(). I would only store the hash result. Storing the image itself is silly.
And double hashing is less secure; just so you know before you try it.
Posted: Sat Aug 19, 2006 12:29 am
by Light
feyd thank you,