對於我正在構建的網站,我需要調整一些圖片的大小以使網頁加載更輕。我用這個代碼:圖片調整大小php
list($width, $height, $type, $attr) = getimagesize($img_path);
$thumb = imagecreatetruecolor(50, 50 * $height/$width);
if($type == 2) $source = imagecreatefromjpeg($img_path);
if($type == 3) $source = imagecreatefrompng($img_path);
imagecopyresized($thumb, $source, 0, 0, 0, 0, 50, 50 * $height/$width, $width, $height);
現在我可以將它們保存在服務器,讓他們做好準備在必要時但考慮到小空間我可以,我寧願避免。
所以我的問題是:有沒有辦法從我已經有的代碼中創建一個「臨時」圖像並在<img>
標籤內使用它?
例如<img src="$img_resized"/>
。
看看[TimThumb](https://www.binarymoon.co.uk/projects/ timthumb /) – gaganshera
參考這個http://stackoverflow.com/questions/3971841/how-to-resize-images-proportionally-keeping-the-aspect-ratio –