目前我正在使用 imagepng 将基于原始图像的图像资源转换为 png 图像类型。事实证明,这比为我的 jpg 创建的 imagejpeg 函数具有更高的质量水平。
但是,您可以清楚地看到,这两个函数中的压缩算法的质量不如 Photoshop 之类的函数。
有谁知道获得更高质量jpeg的方法?是否有关于图像资源格式以及如何将其转换为 jpeg 或 png 的文档?如果我有这些信息,我至少可以尝试实现更好的算法。
//Create image
$im = apppic($filename, $colors);
imagepng($im, "images/app/".rtrim($path_array[$count],"jpeg")."png", 0);
function promopic ($filename, $colors){
if(@imagecreatefromjpeg($filename))
$img = imagecreatefromjpeg($filename);
elseif(@imagecreatefrompng($filename))
$img = imagecreatefrompng($filename);
elseif(@imagecreatefromgif($filename))
$img = imagecreatefromgif($filename);
$width = imagesx($img);
$height = imagesy($img);
$imHeight = 625;
if( $width/$height > 4/5){$imWidth = 800; $imHeight = $height/$width*$imWidth ; }
else { $imWidth = $width/$height*$imHeight; }
$colorWidth = 1200 - $imWidth;
$numColors = count($colors);
$colorHeight = ceil($imHeight/$numColors) - 2;
$imHeight = ceil($imHeight/$numColors)* $numColors - 2;
$im = @imagecreate(1200, $imHeight+50)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 250, 250, 250);
$text_color = imagecolorallocate($im, 255, 255, 251);
$blue_color = imagecolorallocate($im, 40, 5, 251);
//Add color boxes
for ($i = 1; $i <= $numColors; $i++) {
$imcolorbox = @imagecreate($colorWidth, $colorHeight);
$rgb = hex2rgb($colors[($i-1)]);
$colorbox_color = imagecolorallocate($imcolorbox, $rgb[0], $rgb[1], $rgb[2]);
$dest_x = 1200-$colorWidth;
$dest_y = ($colorHeight + 2) * ($i-1);
$copy_image = imagecopy($im, $imcolorbox, $dest_x, $dest_y, 0, 0, $colorWidth, $colorHeight);
imagedestroy($imcolorbox);
//imagestring($im, 5, 1075, 2+$dest_y, "Reinvogue.com", $text_color);
//imagestring($im, 5, $imWidth+5, 2+$dest_y, "Reinvogue.com", $text_color);
//imagestring($im, 5, 1050, 17+$dest_y, "Hex: ".$colors[($i-1)], $text_color);
//imagestring($im, 5, 1050, 2+$dest_y, "RGB: ".$rgb[0]." ".$rgb[1]." ".$rgb[2], $text_color);
}
imagestring($im, 5, 10, $imHeight+15, "Powered by the Reinvogue.com Colorway Engine", $blue_color);
$copy_image = imagecopyresampled($im, $img, 0, 0, 0, 0, $imWidth-2, $imHeight, $width, $height);
return $im;
}