Jump to content

Combining images with php (GC)


pleek

Recommended Posts

Ok, so im learning GC and alls going well but im stuck. The second image that is supposed to merge with $background isn't showing up.

 

<?php

header('Content-type: image/png');
$String = $_GET['text'];
$UserRank = imagecreatefrompng('elitemember.png');
$UserAvatar = imagecreatefromgif('avatar.gif');
$Background = imagecreatefrompng('Background.png');
$TextColor = imagecolorallocate($Background, 225, 225, 225);
$Font = imageloadfont('Kozuka Gothic Pro B.gdf');
imagestring($Background, $Font, 90, 15, $String, $TextColor);
imagecopymerge($Background, $UserRank, 110, 55, 0, 0, 128, 28, 100);
imagecopymerge($Background, $UserAvatar, 20, 20, 0, 0, 160, 160, 100);
imagepng($Background);
imagedestroy($Background);
imagedestroy($UserRank);
imagedestroy($UserAvatar);
?>

 

The image $UserAvatar is not showing up but $UserRank is. Also how can i stop the transparent parts in $background from turning black? Here is the result

Link to comment
https://forums.phpfreaks.com/topic/160572-combining-images-with-php-gc/
Share on other sites

if you clicked the "here is the result" link you can see how big userrank is. It 128 * 28. And im not sure how to set the transparency for $background. How do i do that? And yes i know its GD not GD. But i didn't notice my error till after i posted it and it won't let me edit it.

bump* i can put as many pngs as i want using imagecopymerge and imagecopy. But beyond the background gif i can't get any more gifs to work. And now that i got the transparencies working the imagestring won't show up. heres the new code.

 

 

<?php

header('Content-type: image/png');

// Set a White & Transparent Background Color
$new_image = ImageCreateTruecolor(345, 130);
$bg = ImageColorAllocateAlpha($new_image, 255, 255, 255, 127); // (PHP 4 >= 4.3.2, PHP 5)
ImageFill($new_image, 0, 0 , $bg);


$String = $_GET['text'];
$UserRank = imagecreatefrompng('elitemember.png');
$UserAvatar = imagecreatefrompng('avatar.png');
$Background = imagecreatefromgif('Background.gif');
$TextColor = imagecolorallocate($Background, 225, 225, 225);
$Font = imageloadfont('Kozuka Gothic Pro B.gdf');
imagecopymerge($new_image, $Background, 0, 0, 0, 0, 345, 130, 50);
imagecopymerge($new_image, $UserRank, 110, 55, 0, 0, 128, 28, 100);
imagecopy($new_image, $UserAvatar, 0, 0, 0, 0, 128, 128);
imagestring($new_image, $Font, 90, 15, $String, $TextColor);
imagepng($new_image);
imagedestroy($new_image);
imagedestroy($Background);
imagedestroy($UserAvatar);
imagedestroy($UserRank);
?>

 

view it here

Archived

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

×
×
  • 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.