我有一个类来读取和输出图像内容,如果设置了$ width,它将调整图像大小,然后输出它.
如果我像这样调用函数$ image-> readImage('123.jpg'); ,它可以正确输出图像文件,但是当我调用$ image-> readImage('123.jpg',300)时; 要调整大小,它只显示一个调整宽度和高度的黑色图像.
我试图替换代码
@imagejpeg($thumb, null, 100);
Run Code Online (Sandbox Code Playgroud)
至
@imagejpeg($image, null, 100);
Run Code Online (Sandbox Code Playgroud)
会工作〜
-
protected function readImage($fileName, $width = 0)
{
if ($width <= 0) {
return @file_get_contents($this->destination . '/' . $fileName);
} else {
$imageSize = @getimagesize($this->destination . '/' . $fileName);
$actualWidth = $imageSize[0];
$actualHeigth = $imageSize[1];
if ($actualWidth <= $width) {
return @file_get_contents($this->destination . '/' . $fileName);
}
$height = (100 / ($actualWidth / $width)) * .01;
$height = @round($actualHeigth * $height);
$image …Run Code Online (Sandbox Code Playgroud)