Esempio n. 1
0
 public function testIfImageGDWorks()
 {
     $this->assertNotEmpty(Image::open(__DIR__ . '/dummy/dummy.jpg'));
 }
Esempio n. 2
0
 /**
  * Handle all IMAGES file formats.
  *
  * @param  string $fileInfo uploaded file information the same as $_FILE['input name'] + pathinfo['file name']
  * @param  string $filename filename to save the new file
  */
 private function handleImage($fileInfo, $filename)
 {
     if ($this->size && is_array($this->size)) {
         foreach ($this->size as $size => $config) {
             $newPath = $this->path . $size . '/';
             self::directorize($newPath);
             $newPath = $this->prefix . $newPath . $filename;
             $quality = isset($config['quality']) ? $config['quality'] : $this->quality;
             $file = Image::open($fileInfo['tmp_name']);
             $size = $file->getSize();
             switch ($config['resize']) {
                 case 'widen':
                     $file = $file->resize($size->widen($config['width']));
                     break;
                 case 'heighten':
                     $file = $file->resize($size->heighten($config['height']));
                     break;
                 case 'max':
                     if ($size->getWidth() > $config['width']) {
                         $file = $file->resize($size->widen($config['width']));
                     }
                     if ($size->getHeight() > $config['height']) {
                         $file = $file->resize($size->heighten($config['height']));
                     }
                     break;
             }
             if ($config['crop']) {
                 $size = new Box($config['width'], $config['height']);
                 $mode = ImageInterface::THUMBNAIL_OUTBOUND;
                 $file = $file->thumbnail($size, $mode);
             }
             $tmpPath = $fileInfo['tmp_name'] . '.' . $fileInfo['extension'];
             $file->save($tmpPath, ['quality' => $quality]);
             File::move($tmpPath, $newPath);
         }
     }
 }