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

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

【问题讨论】:

    标签: php image-manipulation gd


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-12
      • 2021-11-06
      • 2010-12-11
      • 2011-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多