create a background for image
I have $new_img = ImageCreateTrueColor(95, 75);
I want to create a 600x400 black background for the #new_img, then center the $new_img vertically and horizontally inside the background.
which function can help me do this ?
Off the top of my head, I think you could just create the black image, and then use imagecopy() to copy the other image into it. dst_y and dst_x would be the upper left coordinates of where you want the small image to be placed.
Btw- you could do this with css.
The easy way is use Imagemagick
With GD you will need to:
Get the size of the large image and the small image.
Take the width of the small image from the width of the large image then divide it by 2 - this will be your "x" position.
Do the same for the height to get your "y" position.
Then use: imagecopymerge()
A couple of GD examples on my site: http://www.rubblewebs.co.uk/imagemagick/GDexamples.php & http://www.rubblewebs.co.uk./imagemagick/compair.php
Last edited by Rubble; May 15, 2009 at
Reason: Added second link
Yes this can be done with css, I just forget that LOL.
Originally Posted by
@Rubble: thank you very much, will play it next time, at the moment i'm going with the css solution.