特定のサイズの画像がいくつかあり、それらを縮小したい。
縮小して保存するのではなく、画像がブラウザに読み込まれるたびにサイズを変更したい
私は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
誰でもこれに光を当てることができますか?このプロセスがどのように機能するかをよく理解していないようです
ありがとう