Example #1
0
 /**
  * Help complete the resize of image
  *
  * @param int $width
  * @param int $height
  * @param string $fit
  * @param string $any
  * @return \iDocrea8\Image\ImageProcessor
  */
 protected function doResize($filename, $width, $height, $fit, $any)
 {
     list($basePath, $baseDir) = $this->processPath();
     $destinationPath = $basePath . $filename;
     try {
         if ($this->isGif() and $this->allowGif) {
             $gif = new \GIF_eXG($this->uploadFilePath, 1);
             $gif->resize($destinationPath, $width, $height, 1, 0);
         } else {
             $layer = \PHPImageWorkshop\ImageWorkshop::initFromPath($this->uploadFilePath, true);
             if ($width < 600) {
                 $layer->cropMaximumInPixel(0, 0, "MM");
                 $layer->resizeInPixel($width, $height);
             } else {
                 $layer->resizeInPixel($width, null, true);
             }
             $layer->save($basePath, $filename);
         }
         if ($this->cdn) {
             $CDNRepository = app('App\\Repositories\\CDNRepository');
             $newFileName = $CDNRepository->upload($destinationPath, $baseDir . $filename);
             if ($newFileName != $filename) {
                 //that means file has been succcessfully uploaded to a CDN Server so
                 $fullFileName = str_replace($width, '%d', $newFileName);
                 $this->result = $fullFileName;
             }
         }
     } catch (\Exception $e) {
         $this->hasError = true;
     }
     return $this;
 }
Example #2
0
 /**
  * Help complete the resize of image
  *
  * @param int $width
  * @param int $height
  * @param string $fit
  * @param string $any
  * @return \iDocrea8\Image\ImageProcessor
  */
 protected function doResize($filename, $width, $height, $fit, $any)
 {
     list($basePath, $baseDir) = $this->processPath();
     $destinationPath = $basePath . $filename;
     try {
         if ($this->isGif() and $this->allowGif) {
             $gif = new \GIF_eXG($this->uploadFilePath, 1);
             $gif->resize($destinationPath, $width, $height, 1, 0);
         } else {
             $wideImage = \WideImage::load($this->uploadFilePath);
             $ort = $this->getOrientation($this->uploadFilePath);
             if ($ort) {
                 $wideImage = $wideImage->exifOrient($ort);
             }
             $wideImage = $wideImage->resize($width, $height, $fit, $any);
             $wideImage->saveToFile($destinationPath);
         }
         if ($this->cdn) {
             $CDNRepository = app('App\\Repositories\\CDNRepository');
             $newFileName = $CDNRepository->upload($destinationPath, $baseDir . $filename);
             if ($newFileName != $filename) {
                 //that means file has been succcessfully uploaded to a CDN Server so
                 $fullFileName = str_replace($width, '%d', $newFileName);
                 $this->result = $fullFileName;
             }
         }
     } catch (\Exception $e) {
         $this->hasError = true;
     }
     return $this;
 }