Insert Gif in PNG using GD

Need help with Photoshop, the GIMP, Illustrator, or others? Want to show off your work? Looking for advice on your newest Flash stuff?

Moderator: General Moderators

Post Reply
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Insert Gif in PNG using GD

Post by snicolas »

Hey,

I am creating PNG file from text data.
This is working well.

Now I would like to insert an existing GIF image in my newly created PNG image.

Is this possible?

s
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post by Robert Plank »

Yes, you can use ImageCreateFromGIF to create an image based on the GIF and then either put your text in that image, or use imagecopyresized() to copy one to the other, depends on what you want to do exactly. Go look those functions up on PHP.net.
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Post by snicolas »

sorry, do you have some code example?
s
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Post by snicolas »

got it working, thanks for advice....
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post by Robert Plank »

Code: Select all

<?php

// Create image from GIF
$im = @imagecreatefromgif ("sample.gif");

// Write blue text on the top left corner
$color = imagecolorallocate($im, 0, 0, 255);
imagestring($im, 5, 0, 0, "1234567890abcdefhijklmnopqrstuvwxyz", $color);

// Output as PNG
header("Content-type:image/png");
imagepng($im);

// Clean-up
imagedestroy($im);

?>
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Post by snicolas »

Thanks Robert,

I have one more question....
I am trying to create an image from a php loop
<?php while{
//insert data here
}
?>

When i do that my last data is correctly inserted, but i am missing all previous rows..
I understand that the PNG actually overwrite itself with latest row found.
Is there a way i can say to add extra "10px" or go to a new row?
ImageTTFText ($im2, 8, 0, 150, 15 + 5 pixel?)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Moved to Graphics.

Why not create the string you wish to draw first?
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post by Robert Plank »

Yeah if you put that whole thing into the loop, it will load the gif over and over each time (BAD).

Create the image from the gif before the loop, then like you said inside the loop do something to increase the Y offset like:

Code: Select all

ImageTTFText ($im2, 8, 0, 150, 15 + (5 * $i++))
Post Reply