【问题标题】:how to find the width and height of an image in image extention in yii如何在yii的图像扩展中找到图像的宽度和高度
【发布时间】:2014-07-12 16:54:21
【问题描述】:

我使用了图片扩展来调整图片大小。它工作正常。这是代码

 $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

【问题讨论】:

  • 你大概可以分别得到像$image->width();$image->height();这样的宽度和高度。 Here is the Reference
  • @ThinkDifferent 出现致命错误:调用未定义的方法 Image::width()

标签: php yii yii-extensions


【解决方案1】:

使用下面的代码

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-25
      • 1970-01-01
      • 2021-05-16
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-07
      • 2011-06-12
      相关资源
      最近更新 更多