views:

91

answers:

2

Hello, how can I do this? I have an image 50x50 and I would like to generate one with 100x100, where the original 50x50 will be centered inside of that one. The rest would be filled with "transparent". Thanks

A: 

Did you ever try an example from the imagecopy manual page?

Col. Shrapnel
php.net????? OMG I will never ever will have to use stackoverflow again!! Thanks a lot for telling me about that website! I am soooo blind!
Luis
@Luis I'm glad you liked it. You are welcome.
Col. Shrapnel
+1  A: 

This is how you do it:

$old = imagecreatefromjpeg("old_image.jpg"); 
// Create a 100x100 image
$im = imagecreatetruecolor(100, 100);
$black = imagecolorallocate($im, 0, 0, 0);

// Make the background transparent
imagecolortransparent($im, $black);

// Copy old image on top of new image
imagecopy($im, $old, 25, 25, 0, 0, 50, 50); 

// Save the image
imagepng($im, './new_image.png');
imagedestroy($im);
David Titarenco
why the downvote ;[
David Titarenco