我有以下php和imagick脚本动态调整图像大小:
resize.php
$_size = $_GET['size'];
$_path = $_GET['path'];
$img = new Imagick($_path);
$img_d = $img->getImageGeometry();
$img_w = $img_d['width'];
$img_h = $img_d['height'];
..// more variables
$crop_w = round($_size * $p_w);
$crop_h = round($_size * $p_h);
list($_w, $_h) = scaleProportions($crop_w, $crop_h, $img_w, $img_h);
$img->resizeImage($_w, $_h, imagick::FILTER_LANCZOS, 0);
header("Content-Type: image/jpg");
header("Cache-control: Public");
$headerTimeOffset = 60 * 60 * 24 * 30;
$headeExpire = "Expires: ".gmdate("D, d M Y H:i:s",time()+$headerTimeOffset)." GMT";
header ($headeExpire);
$img->setImageFormat('jpg');
$img->setImageCompression(Imagick::COMPRESSION_JPEG);
$img->setImageCompressionQuality($_quality);
echo $img->getImageBlob();
我在我的img标签中调用此脚本如下:
images.html
<img src="http:www.mysite.com/resize/size/path" alt="xxxx">
这是按预期工作的。我现在不仅需要获得新调整大小的图像,还需要新的调整大小的尺寸。无论如何这可能吗?
这样做的原因是我在每个图像上使用砌体插件和延迟加载,并希望在加载之前设置网格。我知道在图像加载之前,砌体需要这些尺寸
答案 0 :(得分:0)
效率低下的方法是:
h3
或者将调整大小的图像保存到磁盘,在文档根目录下的某处,获取src的weblink和 getimagesize 的路径。