webster08 Posted June 12, 2011 Share Posted June 12, 2011 I am trying to create a completely PHP GD image based advert, so far I am able to add shapes, lines, and text. The next step is to directly embed an image(s) into my base PHP GD image advert. Here's where the problem comes in; I'm not sure how to go about doing this. I don't want to create a separate php file to watermark the main image with external images. I want to be able to directly embed images into the base image. Can anyone advise as to what would be way to accomplish this; my code is below? <?php // set the HTTP header type to PNG header("Content-type: image/png"); // set the width and height of the new image in pixels $width = 1000; $height = 1000; // create a pointer to a new true colour image $im = imagecreatetruecolor($width, $height); // text $mainTitle="2011 Chrystler Town And Country LX"; // font path $font = 'arial.ttf'; // sets background to white $white = ImageColorAllocate($im, 255, 255, 255); ImageFillToBorder($im, 0, 0, $white, $white); // define a black colour $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 525, 100, $white); // display text on image imagettftext($im, 35, 0, 100, 70, $black, $font, $mainTitle); // make a new line and add it to the image ImageLine($im, 0, 100, 1000, 100, $black); // draw rectangle ImageRectangle($im, 0, 0, 999, 999, $black); // add image $pic1="2011-Chysler-Town-And-Country-pic1.jpg"; imagecreatefromjpeg($im, $pic1, 0, 0, 640, 480, 50); // send the new PNG image to the browser ImagePNG($im); // destroy the reference pointer to the image in memory to free up resources imagepng($im); ImageDestroy($im); ?> This is the piece of code that I know is not correct; this is where I need help at. // add image $pic1="2011-Chysler-Town-And-Country-pic1.jpg"; imagecreatefromjpeg($im, $pic1, 0, 0, 640, 480, 50); Quote Link to comment https://forums.phpfreaks.com/topic/239117-how-do-you-directly-embed-an-image-into-another-php-gd-image/ Share on other sites More sharing options...
webster08 Posted June 12, 2011 Author Share Posted June 12, 2011 How about a little direction; any help would be great? Quote Link to comment https://forums.phpfreaks.com/topic/239117-how-do-you-directly-embed-an-image-into-another-php-gd-image/#findComment-1228586 Share on other sites More sharing options...
webster08 Posted June 12, 2011 Author Share Posted June 12, 2011 Ok... let me see if I can get the ball rolling then. Is it possible for me to do this (in some way); with the imagelayereffect() global GD function? Quote Link to comment https://forums.phpfreaks.com/topic/239117-how-do-you-directly-embed-an-image-into-another-php-gd-image/#findComment-1228606 Share on other sites More sharing options...
Alex Posted June 12, 2011 Share Posted June 12, 2011 imagecopymerge is what you're looking for. Quote Link to comment https://forums.phpfreaks.com/topic/239117-how-do-you-directly-embed-an-image-into-another-php-gd-image/#findComment-1228613 Share on other sites More sharing options...
webster08 Posted June 12, 2011 Author Share Posted June 12, 2011 Hey AlexWD, thank you for the reply. Yeah... I looked at that function, but I am having problems figuring out how to incorporate that into my current code. The example in the manual is rather vague; when it comes to inserting an image into your current image. Would I need to create a totally different php file to do this or can I incorporate something like the example (that the manual gives) into my current code? Quote Link to comment https://forums.phpfreaks.com/topic/239117-how-do-you-directly-embed-an-image-into-another-php-gd-image/#findComment-1228617 Share on other sites More sharing options...
Alex Posted June 12, 2011 Share Posted June 12, 2011 First you'll need to create the image resource for the image you want to merge onto your existing GD image: $pic1="2011-Chysler-Town-And-Country-pic1.jpg"; $pic = imagecreatefromjpeg($pic1); Now you can merge your two resources: $im and $pic using imagecopymerge: imagecopymerge($im, $pic, 0, 0, 0, 0, 640, 480, 50); Look at the manual to see what the parameters mean to get exactly what you're after. Quote Link to comment https://forums.phpfreaks.com/topic/239117-how-do-you-directly-embed-an-image-into-another-php-gd-image/#findComment-1228620 Share on other sites More sharing options...
webster08 Posted June 12, 2011 Author Share Posted June 12, 2011 WOW! Thank You So Much AlexWD; That Is Exactly What I Was Wanting To Do! Quote Link to comment https://forums.phpfreaks.com/topic/239117-how-do-you-directly-embed-an-image-into-another-php-gd-image/#findComment-1228629 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.