我使用此代码调整图像大小:
if ($height > $width) {
$divisor = $width / $imgs;
} else {
$divisor = $height / $imgs;
}
$resizedWidth = ceil($width / $divisor);
$resizedHeight = ceil($height / $divisor);
$xOffset = floor(($resizedWidth - $imgs) / 2);
$yOffset = floor(($resizedHeight - $imgs) / 2);
$resized = imagecreatetruecolor($resizedWidth, $resizedHeight);
$thumb = imagecreatetruecolor($imgs, $imgs);
imagecopyresized($resized, $im, 0, 0, 0, 0, $resizedWidth, $resizedHeight, $width, $height);
imagecopyresized($thumb, $resized, 0, 0, $xOffset, $yOffset, $imgs, $imgs, $imgs, $imgs);
imagepng($thumb, "test.png");
$instr = fopen("test.png","rb");
$imageThumb = addslashes(fread($instr,filesize("test.png")));
风景效果很好,但是当我上传肖像时,缩略图会被加载,直到完全看到,然后它就会消失。