Просмотр поста

.
Folour
Think different

Макс, ну что это такое?

private function createThumb($imagesize){
        // Ширина / высота
$srcW = $this->imageproperties[0];
$srcH = $this->imageproperties[1];
// Перегоняем размеры

        if($this->size){
  
          // Непропорциональный перегон
$copy = imagecreatetruecolor($this->weight, $this->height);
imagecopyresampled($copy,$this->image,0,0,0,0,$this->weight, $this->height, $srcW, $srcH)
 or die ('Не удалось создать копию изображения для обработки.');
//Удаляем оригинал
imagedestroy($this->image);
$this->image = $copy;
            
}elseif(($srcW >$imagesize || $srcH > $imagesize) && $imagesize != 0){
  
          // Порциональный перегон
$reduction = $this->calculateReduction($imagesize);
//Получаем пропорциональные размеры
  $desW = $srcW/$reduction;
  $desH = $srcH/$reduction;
        $this->weight = $desW;
        $this->height = $desH;
$copy = imagecreatetruecolor($desW, $desH);
imagecopyresampled($copy,$this->image,0,0,0,0,$desW, $desH, $srcW, $srcH)
 or die ('Не удалось создать копию изображения для обработки.');
//Удаляем оригинал
imagedestroy($this->image);
$this->image = $copy;

        }else{
            
            // Оригинальные размеры
            $this->weight = $srcW;
            $this->height = $srcH;
}
}


Вот то же самое, после рефакторинга
private function createThumb($imageSize){
        list($srcW, $srcH) = array($this->imageproperties[0], $this->imageproperties[1]);
        if($this->size || (($srcW >$imageSize || $srcH > $imageSize) && $imageSize != 0)) {
            if(!$this->size) {
                $reduction = $this->calculateReduction($imageSize);
                list($this->weight, $this->height) = array($srcW/$reduction, $srcH/$reduction);
            }

            $copy = imagecreatetruecolor($this->weight, $this->height);
            imagecopyresampled($copy,$this->image,0,0,0,0,$this->weight, $this->height, $srcW, $srcH);
            imagedestroy($this->image);
            $this->image = $copy;
        } else list($this->weight, $this->height) = array($srcW, $srcH);
    }