我很确定我需要使用imagefilledrectangle以获得白色背景而不是黑色……只是不确定如何。我已经尝试了几种方法。

$targetImage = imagecreatetruecolor($thumbw,$thumbh);
imagecopyresized($targetImage,$sourceImage,0,0,0,0,$thumbWidth,$thumbHeight,imagesx($sourceImage),imagesy($sourceImage));

最佳答案

更新(2020):请查看以下答案,以获取比imagefill更快的填充速度:https://stackoverflow.com/a/32580839/1005039
原始
PHP manual entry for imagefill:

$image = imagecreatetruecolor(100, 100);

// set background to white
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);

关于php - imagecreatetruecolor具有白色背景,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8135271/

10-10 14:44