Jump to content

Archived

This topic is now archived and is closed to further replies.

CanMan2004

saving GD image

Recommended Posts

Hi all

I have a simple php script to covert text into a image using the GD libary, the code I use is

[code]$handle = ImageCreate (275, 384) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 255, 255, 255);
$txt_color = ImageColorAllocate ($handle, 0, 0, 0);
ImageTTFText ($handle, 8, 180, 270, 360, $txt_color, "arial.ttf", "test text");
ImagePng ($handle);[/code]

with the above, the text "test text" is converted into a image.

What I want to do is to take the image that it creates and upload it onto my server for use later, I tried with the code

[code]$addimage_name = $handle;
$upfile = "../tmpimg/".$addimage_name;

if (!copy($handle, $upfile))
{
print "Could not move image into image directory";
exit;
}
$upfile = $addimage_name;[/code]

But it doesnt seem to work, no matter how I tweak it. Could someone give me help on how I can do this.

Many thanks in advance

Cheers

Ed

Share this post


Link to post
Share on other sites
imagepng() has a second argument - filename, so

$handle = ImageCreate (275, 384) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 255, 255, 255);
$txt_color = ImageColorAllocate ($handle, 0, 0, 0);
ImageTTFText ($handle, 8, 180, 270, 360, $txt_color, "arial.ttf", "test text");
ImagePng ($handle, 'myimage.png');                                                    // <- specify filename
ImageDestroy($handle);                                                                    // remove from memory

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.