我有一些图像有一定的大小,我想缩小它们。
我不想将它们保存为缩放,我想每次在浏览器中加载图像时重新调整它们的大小
我看了一下WideImage图书馆和imagecopyresampled
如果我使用WideImage::load($_GET['img'])->resize(500, 300)->output('jpg', 90);,并且回显出来,我会从图像中获取源代码,而不是实际的图像。
我也提供这种方法
public function resizeImage($originalImage,$toWidth,$toHeight)
{
list($width, $height) = getimagesize($originalImage);
$xscale=$width/$toWidth;
$yscale=$height/$toHeight;
if ($yscale>$xscale){
$new_width = round($width * (1/$yscale));
$new_height = round($height * (1/$yscale));
}
else {
$new_width = round($width * (1/$xscale));
$new_height = round($height * (1/$xscale));
}
$imageResized = imagecreatetruecolor($new_width, $new_height);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
return $imageResized;
}如果我将图像传递给它并回显结果,我会得到resource(192) of type (gd)而不是图像。
也不知道什么图像路径传递给这个方法,http://.....jpg或/var/www/images/....jpg
任何人都可以在此点上一些灯光?它看起来像我不真正了解这个过程如何工作
谢谢