【问题标题】:PHP Imagick - output resized image AND its dimensionsPHP Imagick - 输出调整大小的图像及其尺寸
【发布时间】:2015-06-12 13:15:38
【问题描述】:

我有以下 php 和 imagick 脚本来动态调整图像大小:

调整大小.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">

这按预期工作。我现在不仅需要获得新调整大小的图像,还需要获得新调整大小的尺寸。这有可能吗?

这样做的原因是我在每个图像上使用了 masonry 插件和延迟加载,并希望在它们加载之前设置网格。我知道在图像加载之前砌体需要这些尺寸

【问题讨论】:

    标签: php imagick dimensions masonry


    【解决方案1】:

    低效的小方法是:

    list($width, $height) = getimagesize("http://www.example.com/resize/size/path");
    

    或者将调整大小的图像保存到磁盘,在文档根目录下的某个位置,获取 src 的网络链接和 getimagesize 的路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 2012-01-27
      • 1970-01-01
      • 2021-07-20
      • 2023-03-16
      • 2013-05-25
      相关资源
      最近更新 更多