如何在yii中找到图像扩展中图像的宽度和高度

时间:2014-05-23 10:57:00

标签: php yii yii-extensions

我使用了二手图像扩展来调整图像大小。它的工作正常。这是守则

 $image = Yii::app()->image->load(Yii::getPathOfAlias('webroot').'/files/galaryimages/'.$fileName);
 $image->resize(900, 600)->quality(75)->sharpen(20);
 $image->save();


但是只有在图像尺寸大于固定宽度和高度时才需要调整大小我该怎么做?   
http://www.yiiframework.com/extension/image/#hh5

2 个答案:

答案 0 :(得分:1)

使用以下代码

list($width1, $height1, $type1, $attr1) = getimagesize(Yii::getPathOfAlias('webroot').'/files/images/'.$fileName);
 if(($width1>$width) || ($height1>$height))
 { 
     //code to resize 
  }

答案 1 :(得分:1)

您可以通过widthheight属性访问它们:

echo $image->width . 'x' . $image->height;