Jump to content

PHP GD immagecopy problem


dvwyngaa

Recommended Posts

Hi,

I want to add an icon (16x16px), black and white in .png format to an existing .png file with bunch of text. What I get is a black square on top of the image with the text. Neither of the images have any transparent background. The code I used is as follows:

<?php
$source=imagecreatefrompng("message.png");
$img_get=imagecreatefrompng("smiley1.png");

imagecopy($source,$img_get, 5, 12, 20, 20, 20, 20);

header('Content-Type: image/png');
imagepng($source);
imagedestroy($source);
imagedestroy($img_get);
?>

Any ideas why this doing this, the black squared instead of the actual icon picture (see attached screenshot)? Any suggestions welcome!

Regards,

Dawid

 

post-154562-0-65739500-1369310147_thumb.png

Link to comment
https://forums.phpfreaks.com/topic/278320-php-gd-immagecopy-problem/
Share on other sites

I think you should create a new canvas and then to put this two images all together inside it.

 

I've made a quick test and it's work with jpeg:

<?php
ini_set("display_errors", true);
error_reporting(-1);

$canvas = imagecreatetruecolor(200, 200);

$img1 = imagecreatefromjpeg('images/centos.jpeg');
$img2 = imagecreatefromjpeg('images/redhat.jpeg');

imagecopy($canvas, $img1, 0, 20, 0, 0, 100, 100);
imagecopy($canvas, $img2, 0, 10, 0, 0, 100, 100);

header('Content-Type: image/jpg');
// ... copy additional source images to the canvas as needed
imagejpeg($canvas);

PS. I am not familiar with GD ;)

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.