【发布时间】:2017-03-09 21:50:50
【问题描述】:
我有一个透明背景的 PNG 图像,我想创建一个白色背景的渐进式 JPEG,任何解决方法都非常感谢,从 PNG 创建 PJPEG 是正确的吗?
以下是我的解决方法,我只是想知道这种方法是否正确。
$filePath = 'a.png';
$savePath = 'a.jpeg';
$colorRgb = array('red' => 255, 'green' => 255, 'blue' => 255);
$img = @imagecreatefrompng($filePath);
$width = imagesx($img);
$height = imagesy($img);
$backgroundImg = @imagecreatetruecolor($width, $height);
$color = imagecolorallocate($backgroundImg, $colorRgb['red'], $colorRgb['green'], $colorRgb['blue']);
imagefill($backgroundImg, 0, 0, $color);
imagecopy($backgroundImg, $img, 0, 0, 0, 0, $width, $height);
imageinterlace($backgroundImg, 1);
imagejpeg($backgroundImg, $savePath, 80);
【问题讨论】:
-
查看imagemagick 来执行此操作。此外,这个SO post 将向您展示许多 php 库来完成工作。
-
谢谢! @NiketPathak,将寻找其他选项。
-
@Anand 使用 PHP 的 Imagick 函数。它是 PHP 的简单图像修饰符。 php.net/manual/en/book.imagick.php
-
@SaurabhBhandari :你能看看详细的问题,让我知道你的想法吗?