Пример #1
0
 /**
  * Save the image 
  *
  * When you set the file to null the image will be send to the output buffer.
  *
  * Examples:
  *     $image = CCImage::create( 'path/to/my/image.jpg' );
  *     // save to file
  *     $image->save( 'my/new/image.jpg' );
  *     // quality (80%) and type (gif) 
  *     $image->save( 'my/new/image.gif', 'gif', 80 );
  *     // send to output buffer
  *     $image->save( null );
  *
  * @param string		$file
  * @param int		$quality 	between 1-100
  * @param string		$type
  *
  * @return bool
  */
 public function save($file, $quality = null, $type = null)
 {
     $type = $this->set_type($type);
     // create directory if not exists
     if (!is_null($file)) {
         CCFile::mkdir($file);
     }
     switch ($type) {
         // PNG images
         case 'png':
             if (is_null($quality)) {
                 $quality = -1;
             } else {
                 $quality = $quality / 100 * 9;
             }
             return imagepng($this->image_context, $file, $quality);
             break;
             // GIF images
         // GIF images
         case 'gif':
             return imagegif($this->image_context, $file);
             break;
             // JPEG images
         // JPEG images
         case 'jpeg':
         default:
             if (is_null($quality)) {
                 $quality = 90;
             }
             return imagejpeg($this->image_context, $file, $quality);
             break;
     }
 }