Jump to content

saving GD image


CanMan2004

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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.