dvwyngaa Posted May 23, 2013 Share Posted May 23, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/278320-php-gd-immagecopy-problem/ Share on other sites More sharing options...
jazzman1 Posted May 23, 2013 Share Posted May 23, 2013 Not sure where could be the problem but can you put down that on the top of the script: ini_set("display_errors", true); error_reporting(-1) Quote Link to comment https://forums.phpfreaks.com/topic/278320-php-gd-immagecopy-problem/#findComment-1431820 Share on other sites More sharing options...
dvwyngaa Posted May 23, 2013 Author Share Posted May 23, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/278320-php-gd-immagecopy-problem/#findComment-1431832 Share on other sites More sharing options...
mac_gyver Posted May 23, 2013 Share Posted May 23, 2013 what dimensions are the smiley1.png image? it may be that you are just copying a small back section of it onto the other image. Quote Link to comment https://forums.phpfreaks.com/topic/278320-php-gd-immagecopy-problem/#findComment-1431866 Share on other sites More sharing options...
jazzman1 Posted May 23, 2013 Share Posted May 23, 2013 (edited) 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 May 23, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/278320-php-gd-immagecopy-problem/#findComment-1431868 Share on other sites More sharing options...
Eiseth Posted May 23, 2013 Share Posted May 23, 2013 (edited) 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 May 23, 2013 by Eiseth Quote Link to comment https://forums.phpfreaks.com/topic/278320-php-gd-immagecopy-problem/#findComment-1431871 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.