error with imagecopy!!!

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
sara933
Forum Newbie
Posts: 11
Joined: Thu May 15, 2008 10:01 am

error with imagecopy!!!

Post by sara933 »

hi friends
a question:
i want to fetch an image(type:blob) from sql database and then copy it to another image with imagecopy().i use this :
....$row=mysql_fetch_query($query);
$content=$row['image'];

imagecopy($image,$content,0,0,0,0,$w,$h);
imagejpeg($image);
(header is sent and $image made by imagecreate())
but the error says:imagecopy():supplied argument is not a valid image resource
why here is this error
is it nessasary that i first stor the image in a binary temprary file and then send it to the function???
regards
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: error with imagecopy!!!

Post by onion2k »

When you fetch the data from the database it's just a blob of binary data ... PHP doesn't know it's an image. You need to tell it that it is. Use...

Code: Select all

$image = imagecreatefromstring($content);
You should then be able to use $image where you tried to use $content before.
sara933
Forum Newbie
Posts: 11
Joined: Thu May 15, 2008 10:01 am

Re: error with imagecopy!!!

Post by sara933 »

thank u very much onion2k it works :D :D :D
Post Reply