繁体   English   中英

从PHP GD使用`imagecopyresampled`调整图像大小

[英]Resizing images with `imagecopyresampled` from PHP GD

使用PHP GD库,我生成的图像资源是不透明的白色,到处都有一些“孔”,它们是完全透明的磁盘形状。 我将它附加在下面,尽管由于背景是蓝色,您需要先保存它并使用Image Preview应用程序打开它(在Windows中)才能查看其中的孔。 否则,您只会看到白色。

原始图片: 原始图像资源

从该图像资源(2550 x 3000px),我需要创建一个较小的版本。 我这样做使用imagecopyresampled() 生成的图像一切正常,但有一个例外:到处都是灰色像素(RGB:254,254,254):

调整大小后的图片: 调整大小的图片

我使用的部分代码如下:

$previewPxWidth = $this->viewportWidth_;
$previewPxHeight = round($this->viewportWidth_ / $schematic['paper.aspect.ratio']);

$preview = imagecreatetruecolor($previewPxWidth, $previewPxHeight);
$noColor = imagecolorallocatealpha($preview, 255, 255, 255, 127);
imagesavealpha($preview,true);
imagefill($preview, 0, 0, $noColor);

imagecopyresampled($preview, $sheet, 0, 0, 0, 0, $previewPxWidth, $previewPxHeight, $sheetPxWidth, $sheetPxHeight);
imagedestroy($sheet);

header("Content-type: image/png");
header("Content-disposition: inline; filename=image.png");
imagepng($preview);

那些非常轻且(显然)随机放置的灰色像素从哪里来,我如何摆脱它们?

尝试imageAlphaBlending(),但是ImageMagic是最好的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM