簡體   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