Jump to content


Photo

saving GD image


  • Please log in to reply
2 replies to this topic

#1 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 03 September 2006 - 11:38 PM

Hi all

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

$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);


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

$addimage_name = $handle;
$upfile = "../tmpimg/".$addimage_name;

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

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 03 September 2006 - 11:43 PM

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
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 04 September 2006 - 08:47 AM

thanks very much




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users