如何使用 PHP GD 放大图像?

Posted

技术标签:

【中文标题】如何使用 PHP GD 放大图像?【英文标题】:How to scale up an image with PHP GD? 【发布时间】:2010-03-21 17:03:57 【问题描述】:

我该怎么做?我有一个 50x50 的图像,我想生成一个 100x100 的图像,其中原始的 50x50 将位于该图像的中心。其余的将充满“透明”。 谢谢

【问题讨论】:

【参考方案1】:

这就是你的做法:

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

【讨论】:

以上是关于如何使用 PHP GD 放大图像?的主要内容,如果未能解决你的问题,请参考以下文章