function scaleProportional($width, $height = null, $direction = "center") { if ($height == null) { $height = $width / $this->ratio; } $newRatio = $width / $height; Logger::log("BMP", "ratios = {$this->ratio} = {$newRatio}"); Logger::log("BMP", "dimensions = {$width} x {$height}"); Logger::log("BMP", "og. dimensions = {$width} x {$height}"); $x = 0; $y = 0; if ($newRatio == $this->ratio) { $resultWidth = $this->width; $resultHeight = $this->height; } else { if ($this->ratio > $newRatio) { Logger::log("BMP", "entra aqui >>> "); $resultHeight = $this->height; $resultWidth = $this->height * $newRatio; switch (strtolower($direction)) { case "center": $x = round(($this->width - $resultWidth) / 2); break; case "left": $x = 0; break; case "right": $x = $this->width - $resultWidth; break; } } else { $resultWidth = $this->width; $resultHeight = $this->width / $newRatio; switch (strtolower($direction)) { case "center": $y = round(($this->height - $resultHeight) / 2); break; case "top": $y = 0; break; case "bottom": $y = $this->height - $resultHeight; break; } } } Logger::log("BMP", "result dimensions = {$resultWidth} x {$resultHeight}"); $newImage = imagecreatetruecolor($width, $height); /*switch ($this->extension){ case "jpeg": case "jpg": $newImage = imagecreatetruecolor($width,$height); break; case "gif": $newImage = imagecreate($width,$height); break; }*/ //$newImage = $newMethodName($width,$height); imagecopyresampled($newImage, $this->imageHandler, 0, 0, $x, $y, $width, $height, $resultWidth, $resultHeight); //,$this->width,$this->height); $resultImage = new Bitmap(); $resultImage->setImage($newImage); $resultImage->setExtension($this->extension); return $resultImage; /* @mkdir($this->fileName."_chache",0777,true); imagejpeg($newImage,$this->fileName."_chache/".$width."x".$height.".jpg",90); */ //imagejpeg($thumbImage,$CACHE_BASE."{$thumbWidth}x{$thumbHeight}/".md5($srcImageURI),90); }