/**
  * Rotate image
  * @param string $name Name of rotating file relative to web root.
  * @return string Name of rotated file relative to web root.
  */
 public static function rotate($name, $maxImageWidth, $maxImageHeight, $quality)
 {
     $filename = Yii::getAlias('@webroot') . $name;
     $newName = self::generateName($name);
     $newFilename = Yii::getAlias('@webroot') . $newName;
     $image = new ImageFile($filename, ['jpegQuality' => $quality]);
     $image->rotate(270);
     $image->bounds($maxImageWidth, $maxImageHeight);
     $image->save($newFilename);
     return $newName;
 }
示例#2
0
 /**
  * Render image item.
  * @return string
  */
 protected function renderImage()
 {
     $thumb = $this->thumb;
     if ($thumb === null) {
         $thumb = $this->file;
     }
     list($w, $h) = getimagesize(Yii::getAlias('@webroot') . $thumb);
     list($width, $height) = ImageFile::getBounds($w, $h, $this->width, $this->height);
     $left = ($this->width - $width) / 2;
     $top = ($this->height - $height) / 2;
     $style = "width: {$width}px; height: {$height}px; left: {$left}px; top: {$top}px";
     $image = Html::img($thumb, ['style' => $style]);
     return Html::a($image, $this->file, ['class' => 'uploadimage-image', 'style' => "width: {$this->width}px; height: {$this->height}px;"]);
 }