0

我需要将背景的颜色更改ImageCreateTrueColor为白色,然后在其上放置图像

elseif(($height>50)&&($width<50))
{
    $img_r = imagecreatefromjpeg($new_img_path); 
    $source = ImageCreateTrueColor(50, 50);
    imagetruecolortopalette($source, FALSE, 2);
    $bg = imagecolorat($source, 0, 0);          
    imagecolorset($source, $bg, 0, 0, 255);
    // $white = imagecolorallocate($source,255,255,255);
    // imagefilledrectangle($source, 0, 0, 50, 50, $white);

    imagecopy($source, $img_r,0,0,0,0,$width,50);
    header('Content-type: image/jpeg');
    imagejpeg($source, $small_new_img_path);

这里是蓝色的,不过没关系,它不会把图像放在蓝色背景上

4

1 回答 1

1

你想创建一个 png 而不是 JPEG。使用imagepngimagesavealpha

查看完整示例

于 2013-07-18T08:16:43.350 回答