|
Posted by Rik on 08/16/06 21:17
Mike G. wrote:
Dont toppost...
> Rik wrote:
>> Cleverbum@hotmail.com wrote:
>>> I wanted to check if two images on my server were the same, and had
>>> the bright idea of using:
>>>
>>> $a=imagecreatefromjpg("1.jpg");
>>> $b=imagecreatefromjpg("2.jpg");
>>>
>>> if($a==$b){
>>> echo "they match";
>>> }else{
>>> echo "they don't match";
>>> }
>>>
>>> But that won't work, I obviously can't use equality to compare them,
>>> but is there a way that I can?
>>
>>
>> Yup, it will give a different resource id, even if you use the same
>> image.
>>
>> I'm not sure wether this is good practise but:
>> $a = md5(file_get_contents('1.jpg');
>> $b = md5(file_get_contents('2.jpg');
>> if($a==$b){
>> echo "they match";
>> }else{
>> echo "they don't match";
>> }
> That of course, assumes you're using PHP 5.
Well, PHP >= 4.3 actually, which is the bare minimum you should use anyway.
> Instead of using that
> technique, I would use the md5_file function instead.
>
> http://us2.php.net/manual/en/function.md5-file.php
Which is by far the better solution, I hadn't come across this function yet.
Noted for future reference :-).
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|