我很确定我需要使用imagefilledrectangle来获得白色背景而不是黑色......只是不确定如何.我尝试了几种方法.
$targetImage = imagecreatetruecolor($thumbw,$thumbh);
imagecopyresized($targetImage,$sourceImage,0,0,0,0,$thumbWidth,$thumbHeight,imagesx($sourceImage),imagesy($sourceImage));
Run Code Online (Sandbox Code Playgroud)
Gus*_*ram 35
$image = imagecreatetruecolor(100, 100);
// set background to white
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);
Run Code Online (Sandbox Code Playgroud)
imagefill()使用泛色填充,与仅在矩形中绘制颜色而不考虑图像内容相比,这是非常慢的.所以imagefilledrectangle()会更快.
// get size of target image
$width = imagesx($targetImage);
$height = imagesy($targetImage);
// get the color white
$white = imagecolorallocate($targetImage,255,255,255);
// fill entire image (quickly)
imagefilledrectangle($targetImage,0,0,$width-1,$height-1,$white);
Run Code Online (Sandbox Code Playgroud)
编写代码时,速度通常是一个考虑因素.
| 归档时间: |
|
| 查看次数: |
29730 次 |
| 最近记录: |