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
Share on other sites

jazzman1,

 

Thanks, I did that, but the script doesn't give any errors. I can view both the files (.png's) seperately, but as soon as I use imagecopy or imagecopymerge, the icon appears as a black block on top of the other.

 

Dawid

Link to comment
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 ;)

Edited by jazzman1
Link to comment
Share on other sites

Change this

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

to this 

// because 0, 0 means the copy will start from the top left of the smiley face
// putting 20x20 from a 16x16 picture doesn't make any sense
imagecopy($source,$img_get, 5, 12, 0, 0, 16, 16);
Edited by Eiseth
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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