glenelkins Posted November 2, 2007 Share Posted November 2, 2007 Hi Using the GD functions how can one image be placed ontop of another.. I want to add a border around each uploaded image using another background image as the border...like place the smaller image in the middle of the larger image Quote Link to comment https://forums.phpfreaks.com/topic/75757-place-and-image-onto-another/ Share on other sites More sharing options...
ignace Posted November 2, 2007 Share Posted November 2, 2007 <div style="background:#0c0 url(image1.jpg); border:1px solid #00c; width:500px; height:500px; text-align:center; padding:10px;"> <div style="background:#c00 url(image2.jpg); border:1px solid #0c0; width:480px; height:480px; text-align:center; padding:10px;"> <div style="background:#00c url(image3.jpg); border:1px solid #c00; width:460px; height:460px; text-align:center; padding:10px;"> </div> </div> </div> you do this by placing a div inside another where the parent is the image beneath the child image Quote Link to comment https://forums.phpfreaks.com/topic/75757-place-and-image-onto-another/#findComment-383392 Share on other sites More sharing options...
janim Posted November 2, 2007 Share Posted November 2, 2007 you can do it by table too have a table with one row and one column and let it have your background then inside this cell or table put your uploaded picture Quote Link to comment https://forums.phpfreaks.com/topic/75757-place-and-image-onto-another/#findComment-383402 Share on other sites More sharing options...
severndigital Posted November 2, 2007 Share Posted November 2, 2007 Using the GD functions how can one image be placed on top of another.. Why can't people read the posts before they respond. GD gets tricky when using more than one image. This is how I worked it. This code is pulled from a working script of mine, so some the variables are calling Mysql References. //apply the logo to the base img //set base image $background_file = 'location\to\background\file.png'; //set logo file $source_file = 'images/dimgs/' . $gLogo['logo'] . ''; /* Load a source image and a background */ $iSource = imagecreatefrompng($source_file); $iBackground = imagecreatefrompng($background_file); //resize the overlaid image. $orig_imgsize = getimagesize($source_file); $orig_width = $orig_imgsize['0']; $orig_height = $orig_imgsize['1']; $orig_width = $orig_imgsize['0']; $orig_height = $orig_imgsize['1']; //to resize proportionatley, we must calculate reduction percentage. $final_height = 45; //this is a fixed number //get percentage of original width $perc = $final_height / $orig_height; // use perc to calculate height $final_width = $orig_width * $perc; $img_n = imagecreatetruecolor($final_width,$final_height); $iSourceR = imagecopyresized ($img_n,$iSource,0,0,0,0,$final_width,$final_height,$orig_width,$orig_height); $iMarginW = 5; //$iMaringH = 50; ImagePng($img_n,"images/source.png"); //now we can call this image if it exists. if not we call the default blank template. like i said it GD can get a bit confusing, but it gets the job done. That should get you started at least. wait until you try to apply a text based watermark to a picture within another pic. It take about another 50 lines of code hope this helps, Chris Quote Link to comment https://forums.phpfreaks.com/topic/75757-place-and-image-onto-another/#findComment-383481 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.