Пример #1
0
 /**
  * Returns a new `ImageInterface` instance
  * depending on the given file extension.
  *
  * Currently, these formats are supported:
  *
  * - Jpeg
  * - GIF
  * - PNG
  *
  * @param  string $file Filename
  * @return ImageInterface `JpegImage`, `GifImage` or `PngImage`
  * @throws YaphrException
  *
  * @uses   CheckReadableFile
  * @uses   FileExtension
  * @uses   JpegImage
  * @uses   GifImage
  * @uses   PngImage
  */
 public function newInstance($file)
 {
     new CheckReadableFile($file);
     $extension = new FileExtension($file);
     switch ($extension->__toString()) {
         case 'jpg':
         case 'jpeg':
             return new JpegImage($file);
             break;
         case 'gif':
             return new GifImage($file);
             break;
         case 'png':
             return new PngImage($file);
             break;
         default:
             throw new YaphrException("Could not determine Image class from filename");
             break;
     }
 }
Пример #2
0
 /**
  * @param  resource $image     Image resource or `ImageInterface` instance
  * @param  string   $save_path Where to store that file
  *
  * @uses   SaveImageAbstract::makeSureIsResource()
  * @uses   SaveImageAbstract::makeSureIsString()
  * @uses   FileExtension
  *
  * @throws YaphrException
  */
 public function __construct($image, $save_path, $quality = 100)
 {
     $image = $this->makeSureIsResource($image);
     $save_path = $this->makeSureIsString($save_path);
     $extension = new FileExtension($save_path);
     switch ($extension->__toString()) {
         case 'jpg':
         case 'jpeg':
             return new SaveJpeg($image, $save_path, $quality);
             break;
         case 'gif':
             return new SaveGif($image, $save_path, $quality);
             break;
         case 'png':
             return new SavePng($image, $save_path, $quality);
             break;
         default:
             throw new YaphrException("Could not determine SaveImage class from filename");
             break;
     }
 }