Пример #1
0
 /**
  * Method to write the current image out to a file.
  *
  * @param   string   $path     The filesystem path to save the image.
  * @param   integer  $type     The image type to save the file as.
  * @param   array    $options  The image type options to use in saving the file.
  *
  * @return  void
  *
  * @see     http://www.php.net/manual/image.constants.php
  * @since   11.3
  * @throws  LogicException
  */
 public function toFile($path, $type = IMAGETYPE_JPEG, array $options = array())
 {
     // Make sure the resource handle is valid.
     if (!$this->isLoaded()) {
         throw new LogicException('No valid image was loaded');
     }
     if (is_string($type)) {
         $type = WFImage::getImageType($type);
     }
     switch ($type) {
         case IMAGETYPE_GIF:
             $result = imagegif($this->handle, $path);
             break;
         case IMAGETYPE_PNG:
             $quality = array_key_exists('quality', $options) ? $options['quality'] : 0;
             // get as value from 0-9
             if ($quality) {
                 // png compression is a value from 0 (none) to 9 (max)
                 $quality = 100 - $quality;
                 // convert to value between 0 - 9
                 $quality = min(floor($quality / 10), 9);
             }
             $result = imagepng($this->handle, $path, $quality);
             break;
         case IMAGETYPE_JPEG:
         default:
             $result = imagejpeg($this->handle, $path, array_key_exists('quality', $options) ? $options['quality'] : 100);
     }
     $this->destroy();
     return $result;
 }