Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Overlaps

Status
Not open for further replies.

AcidReignX

Programmer
Feb 28, 2005
32
US
Hello,

I'm trying to develop an avatar system where you can overlap images onto a single image (like put a hat onto a character). I've googled tons of combinations trying to find out how to do this in php, but so far I've had no luck. So here I am.

Anybody here able to direct me to the answer?
 
are all the other images predefined(like the hat) or are they created at runtime? if they are predefined then i would suggest use of layers...

Known is handfull, Unknown is worldfull
 
Predefined as in already drawn and saved as an image? If so, then yes.

And do you perhaps have a good tutorial I could look at for layers. Now that I know a good keyword (can't believe I didn't try that one before... sheesh) I might be able to find something on it, but its odd that it didn't come up with some of the other stuff I tried... hmm...

Well, anyways, if you do have a link to a tutorial, that would be appreciated. I've tried learning from other code, but it doesn't work for some reason (the stuff that I was trying). Here's what I had:

<?php
$im = imagecreatefromgif("images/upleft.gif");
$im2 = imagecreatefromgif("images/topic.gif");

imagecopy ($im, $im2, 0, 0, 0, 0 40, 20);
imagedestroy($im2);

imagegif($im);
imagedestroy($im);
?>

And it gives me this error: Parse error: parse error, unexpected T_LNUMBER

Maybe that helps?
 
thats a PHP error, no idea (i havnt used GD lib much).

Known is handfull, Unknown is worldfull
 
The error is almost certainly from the highlighted portion of this line:

imagecopy ($im, $im2, 0, 0, 0, [red]0 40[/red], 20);


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Here's some sample code you can modify to start you out.
Code:
$img_1_file = (your smaller file here);
$img_1_size = @getimagesize($img_1_file);
$img_1_width = $img_size[0];
$img_1_height = $img_size[1];
$img_1 = imagecreatefrom____($img_1_file);
$img_2_file = (your bigger file here);
$img_2_size = @getimagesize($img_2_file);
$img_2_width = $img_size[0];
$img_2_height = $img_size[1];
$img_2 = imagecreatefrom____($img_2_file);
$dst_x = (smaller picture's left/right location);
$dst_y = (smaller picture's top/bottom location);
imagecopyresampled($img_2,$img_1,$dst_x,$dst_y,0,0,img_2_width,img_2_height,img_1_width,img_1_height)
imagedestroy($img_1);
header("Content-type: image/jpeg");
imagejpeg($img_2);
imagedestroy($img_2);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top