开发者

How to scale up an image with PHP GD?

开发者 https://www.devze.com 2022-12-23 10:28 出处:网络
how can I do this? I h开发者_开发问答ave 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 \"tra

how can I do this? I h开发者_开发问答ave 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


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号