public function resizeImage() { if ($this->getFileType() != self::FILE_IMAGE) { return false; } // узнаем ширину и высоту $w = self::$_maxWidth; $h = self::$_maxHeight; if (!self::$_initSize) { $w = Yii::app()->params['upload_image_width']; $h = Yii::app()->params['upload_image_height']; if ($w == null || !is_numeric($w) || $w < 0) { $w = 0; } if ($h == null || !is_numeric($h) || $h < 0) { $h = 0; } self::$_maxWidth = intval($w); self::$_maxHeight = intval($h); self::$_initSize = true; } if ($w == 0 && $h == 0) { return false; } $path = $this->getFilePath(true); if ($path == null || !file_exists($path)) { return false; } // если размеры меньше $img = new ImageUtils(); $a = $img->info($path); if ($a['width'] <= $w) { $w = 0; } if ($a['height'] <= $h) { $h = 0; } if ($w == 0 && $h == 0) { return false; } if (!$img->open($path)) { return false; } // определяем по ширине или высоте делать ресайз: $newW = $w; $newH = $h; if ($w == 0 && $h != 0) { $newW = round($h * $img->width / $img->height); } else { if ($h == 0 && $w != 0) { $newH = round($w * $img->height / $img->width); } else { $tmpH = round($w * $img->height / $img->width); if ($tmpH > $h) { $newW = round($h * $img->width / $img->height); } else { $newH = round($w * $img->height / $img->width); } } } $img->resize($newW, $newH); $img->save($path, 94); return true; }