Пример #1
0
 /**
  * Save the image based on its file type.
  * @param  string $savePath     Where to save the image
  * @param  int    $imageQuality The output quality of the image
  * @return boolean
  */
 public function save($savePath, $imageQuality = 95)
 {
     // If the image wasn't resized, fetch original image.
     if (!$this->imageResized) {
         $this->imageResized = $this->image;
     }
     // Get extension of the output file.
     $extension = Inflector::lower(File::extension($savePath));
     // Create and save an image based on it's extension.
     switch ($extension) {
         case 'jpg':
         case 'jpeg':
             if (imagetypes() & IMG_JPG) {
                 imagejpeg($this->imageResized, $savePath, $imageQuality);
             }
             break;
         case 'gif':
             if (imagetypes() & IMG_GIF) {
                 imagegif($this->imageResized, $savePath);
             }
             break;
         case 'png':
             // Scale quality from 0-100 to 0-9.
             $scaleQuality = round($imageQuality / 100 * 9);
             // Invert quality setting as 0 is best, not 9.
             $invertScaleQuality = 9 - $scaleQuality;
             if (imagetypes() & IMG_PNG) {
                 imagepng($this->imageResized, $savePath, $invertScaleQuality);
             }
             break;
         default:
             return false;
             break;
     }
     // Remove the resource for the resized image.
     imagedestroy($this->imageResized);
     return true;
 }