Compare two images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Light
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 10:00 pm

Compare two images

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can. It's not fun, but you can.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

What exactly do you want to achieve? Do you want to see if two images are the same or what?
Light
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 10:00 pm

Post by Light »

JayBird,

Yes, I want to see if two images are the same.

==================================

feyd,

Thank you.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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
Last edited by nickvd on Fri Aug 18, 2006 8:11 pm, edited 1 time in total.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

That's what I'd do, except I'd use md5_file() to avoid loading the images into memory. ;-)
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

8O Ya learn something new every day... didn't know that function existed... I'll edit my post :)

Tnx AC!!!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Compare filesize() first, if you're going to run that. If they're different sizes, what's the point of running md5()? :)
Light
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 10:00 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

They're using an image as or in place of a password? Or do you mean a Captcha?
Light
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 10:00 pm

Post by Light »

Hi,

They will use an image in place of a password.

Thank you
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Light
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 10:00 pm

Post by Light »

feyd thank you,
Post Reply