Jump to content

Place and Image Onto Another


glenelkins

Recommended Posts

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

Link to comment
Share on other sites

<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

Link to comment
Share on other sites

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  ;D

 

hope this helps,

Chris

 

 

 

 

 

 

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.