public function process()
 {
     $data = $this->loadData();
     if ($data !== true) {
         return $this->failure($data);
     }
     $mobile = (int) $this->getProperty('mobile', 0);
     if ($mobile == 1) {
         $orientation = $this->img->exif('Orientation');
         switch ($orientation) {
             case 3:
                 $this->img->rotate(180);
                 break;
             case 6:
                 $this->img->rotate(-90);
                 break;
             case 8:
                 $this->img->rotate(90);
                 break;
         }
     }
     if (isset($this->data['rotate'])) {
         $rotate = $this->data['rotate'] * -1.0;
         $this->img->rotate($rotate);
     }
     $crop = $this->getProperty('crop', 0);
     if ($crop == 1 && isset($this->data['width']) && isset($this->data['height'])) {
         $width = intval($this->data['width']);
         $height = intval($this->data['height']);
         if ($height != 0 && $width != 0) {
             $this->img->crop($width, $height, intval($this->data['x']), intval($this->data['y']));
         }
     }
     $fileName = $this->generateUniqueFileName();
     $width = (int) $this->md->getOption('resizer.width', null, 0);
     $width = empty($width) ? null : $width;
     $height = (int) $this->md->getOption('resizer.height', null, 0);
     $height = empty($height) ? null : $height;
     $profileName = $this->getProperty('profile', '');
     if (!empty($profileName) && $crop == 1) {
         $profiles = $this->modx->fromJSON($this->md->getOption('cropper.profiles', null, '[]'));
         foreach ($profiles as $profile) {
             if (!isset($profile['name']) || $profile['name'] != $profileName) {
                 continue;
             }
             $profileWidth = (int) $profile['width'];
             $profileHeight = (int) $profile['height'];
             $width = empty($profileWidth) ? $width : $profileWidth;
             $height = empty($profileHeight) ? $height : $profileHeight;
             break;
         }
     }
     if ($width != null || $height != null) {
         $this->img->resize($width, $height, function ($constraint) {
             /** @var \Intervention\Image\Constraint $constraint */
             $constraint->aspectRatio();
             $constraint->upsize();
         });
     }
     $this->img->save($this->uploadPath . $fileName . '.' . $this->extension);
     return $this->success('', array('path' => $this->uploadURL . $fileName . '.' . $this->extension, 'name' => $this->originalName));
 }
Esempio n. 2
0
 public function save($path)
 {
     $info = pathinfo($path);
     if (!is_dir($info['dirname'])) {
         mkdir($info['dirname'], 0777, true);
     }
     $this->image->save($path);
 }
Esempio n. 3
0
 public function upload()
 {
     try {
         $this->image->save($this->getFullImagePath());
         return true;
     } catch (\Exception $e) {
         $e->getMessage();
         //TODO remove once tested
         return false;
     }
 }
Esempio n. 4
0
 /**
  * Save rendered image to output file
  * @param string $outputImagePath The path to which the image (with text) will be saved
  * @api
  */
 public function render($outputImagePath, $drawtext = true)
 {
     if ($drawtext) {
         $this->drawText();
     }
     $this->image->save($outputImagePath, 100);
 }
Esempio n. 5
0
 /**
  * @param string $path
  * @param null   $quality
  *
  * @return $this
  */
 public function save($path, $quality = null)
 {
     if (!$this->image) {
         throw new \LogicException(sprintf('You must call %s::makeAvatar() first!', __CLASS__));
     }
     $this->image->save($path, $quality);
     return $this;
 }
Esempio n. 6
0
 /**
  * Store the image
  *
  * @param  Image  $image [description]
  * @return void
  */
 public function store(Image $image)
 {
     // We can use .htaccess to use that file instead of rerendering
     // the image
     if (!is_dir($this->directory)) {
         mkdir($this->directory);
     }
     $image->save($this->directory . DIRECTORY_SEPARATOR . $this->filename);
 }
 public function write(Image $file, Picture $picture, array $filters = [])
 {
     $filename = $this->buildFileName($picture, $filters);
     $targetPath = 'files/' . $filename;
     $tempFile = storage_path($targetPath . '.jpg');
     $file->save($tempFile);
     $result = $this->getConnection()->write($filename, IlluminateFile::get($tempFile));
     unlink($tempFile);
     return $result;
 }
Esempio n. 8
0
 /**
  * Close the image and save the changes to a file.
  *
  * @param  string|null $destination Destination path where the image should be saved. If it is empty the original image file will be overwritten.
  * @throws \RuntimeException
  * @return Image  image or false, based on success.
  */
 public function save($destination = null)
 {
     if (empty($destination)) {
         $destination = $this->source;
     }
     $this->image->save($destination);
     // Clear the cached file size and refresh the image information.
     clearstatcache();
     chmod($destination, 0644);
     return new self($destination);
 }
Esempio n. 9
0
 /**
  * Write the re-sized image to the destination path,
  * creating any relative directories necessary.
  *
  * @param $dst_path
  * @param ImageManipulator $image
  * @return bool|Image
  */
 private function writeThumb($dst_path, ImageManipulator $image)
 {
     $parts = explode('/', $dst_path);
     array_pop($parts);
     $path = implode('/', $parts);
     if (!file_exists($path)) {
         if (!mkdir($path, 0775)) {
             return false;
         }
     }
     return $image->save($dst_path);
 }
Esempio n. 10
0
 /**
  * Save file to database and to our filesystem.
  */
 public static function make(Picture $picture, Image $image, $identifier)
 {
     $file = new self();
     $file->picture_id = $picture->id;
     $file->identifier = $identifier;
     $file->mime = $image->mime();
     $file->extension = $image->extension;
     $file->width = $image->width();
     $file->height = $image->height();
     self::checkDirPermission();
     $image->save($file->getFilePath());
     $file->save();
 }
Esempio n. 11
0
 /**
  * Save
  *
  * @param string  $path
  * @param integer $quality
  *
  * @return binary
  */
 public function save($path, $quality = null)
 {
     return $this->image->save($path, $quality);
 }
 /**
  * @param Image $image
  */
 public function saveImage(Image $image)
 {
     $path = dirname($this->cacheFilePath);
     if (!file_exists($path)) {
         mkdir($path, 0777, true);
     }
     $image->save($this->cacheFilePath, $this->quality);
 }
Esempio n. 13
0
 function save($path)
 {
     $this->image->save($path . $this->image->filename . '.jpg');
 }
Esempio n. 14
0
 public function saveImage($path)
 {
     $this->image->save($path);
     return $this;
 }
 /**
  * @param  Image    $processImage
  * @param  Document $rawDocument
  * @return Document
  */
 protected function createDocumentFromImage(Image $processImage, Document $originalDocument, $keepExistingRaw = false)
 {
     $fs = new Filesystem();
     if (false === $keepExistingRaw && null !== ($formerRawDoc = $originalDocument->getRawDocument())) {
         /*
          * When document already exists with a raw doc reference.
          * We have to delete former raw document before creating a new one.
          * Keeping the same document to preserve existing relationships!!
          */
         $originalDocument->setRawDocument(null);
         /*
          * Make sure to disconnect raw document before removing it
          * not to trigger Cascade deleting.
          */
         $this->em->flush();
         $this->em->remove($formerRawDoc);
         $this->em->flush();
     }
     if (null === $originalDocument->getRawDocument() || $keepExistingRaw === false) {
         /*
          * We clone it to host raw document.
          * Keeping the same document to preserve existing relationships!!
          *
          * Get every data from raw document.
          */
         $rawDocument = clone $originalDocument;
         $rawDocumentName = preg_replace('#\\.(jpe?g|gif|tiff?|png|psd)$#', $this->rawImageSuffix . '.$1', $originalDocument->getFilename());
         $rawDocument->setFilename($rawDocumentName);
         if ($fs->exists($originalDocument->getAbsolutePath()) && !$fs->exists($rawDocument->getAbsolutePath())) {
             /*
              * Original document path becomes raw document path. Rename it.
              */
             $fs->rename($originalDocument->getAbsolutePath(), $rawDocument->getAbsolutePath());
             /*
              * Then save downscaled image as original document path.
              */
             $processImage->save($originalDocument->getAbsolutePath(), 100);
             $originalDocument->setRawDocument($rawDocument);
             $rawDocument->setRaw(true);
             $this->em->persist($rawDocument);
             $this->em->flush();
             return $originalDocument;
         } else {
             return false;
         }
     } else {
         /*
          * We keep intact raw document, just updating downscaled doc.
          */
         $rawDocument = $originalDocument->getRawDocument();
         /*
          * Remove existing downscaled document.
          */
         $fs->remove($originalDocument->getAbsolutePath());
         /*
          * Then save downscaled image as original document path.
          */
         $processImage->save($originalDocument->getAbsolutePath(), 100);
         $this->em->flush();
         return $originalDocument;
     }
 }
Esempio n. 16
0
 /**
  * Save image in filesystem
  *
  * @param string $path
  * @param integer $quality
  * @return \Intervention\Image\Image 
  * @static 
  */
 public static function save($path = null, $quality = 90)
 {
     return \Intervention\Image\Image::save($path, $quality);
 }
Esempio n. 17
0
 /**
  * Save rendered image to output file
  * @param string $outputImagePath The path to which the image (with text) will be saved
  * @api
  */
 public function render($outputImagePath)
 {
     $this->drawText();
     $this->image->save($outputImagePath);
 }
Esempio n. 18
0
 /**
  * Save the image.
  *
  * @param string $path
  * @return $this
  */
 public function saveImage($path)
 {
     $this->createDirectoryIfNotExists($path);
     $this->image->save($path);
     return $this;
 }
Esempio n. 19
0
 public function missingMethod($args)
 {
     if (count($args) < 3) {
         return parent::missingMethod($args);
     }
     if ($args[0] == 'force') {
         array_shift($args);
     }
     $modelKeyword = $args[0];
     $modelClass = \Devhook::getClassByKey($modelKeyword);
     $id = $args[1];
     $file = $args[2];
     $parts = explode('-', $file);
     if (count($parts) == 3) {
         list($field, $sizeKey, $file) = $parts;
         @(list($imageId, $ext) = explode('.', $file));
     } else {
         $imageId = false;
         @(list($field, $file) = $parts);
         @(list($sizeKey, $ext) = explode('.', $file));
     }
     if (!$field || !$sizeKey || $ext != 'jpg') {
         return parent::missingMethod($args);
     }
     $model = $modelClass::find($id);
     if (!$model || !$model->{$field}) {
         return parent::missingMethod($args);
     }
     // $fileExt = pathinfo($model->$field, PATHINFO_EXTENSION);
     $fields = (array) $model->getFields();
     $modelField = isset($fields[$field]) ? $fields[$field] : false;
     if (!$modelField || empty($modelField->type)) {
         return parent::missingMethod($args);
     }
     $imageTypes = array('image');
     $type = $modelField->type;
     $sizes = (array) $modelField->settings('sizes');
     $imageAdminThumb = Config::get('devhook.imageAdminThumb');
     if (!in_array($type, $imageTypes) || empty($sizes[$sizeKey])) {
         return parent::missingMethod($args);
     }
     $watermark = $modelField->settings('watermark');
     $size = $sizes[$sizeKey];
     $width = $size[0];
     $hegiht = $size[1];
     $crop = isset($size[2]) ? $size[2] : false;
     $quality = isset($size[3]) ? $size[3] : 95;
     if ($imageId) {
         $imageFile = \Image::where('imageable_type', $modelKeyword)->where('imageable_id', $id)->find($imageId);
         if (!$imageFile) {
             return parent::missingMethod($args);
         }
         $imageFile = $imageFile->path;
     } else {
         $imageFile = $model->{$field};
     }
     ini_set('memory_limit', '200M');
     $image = new IMG(public_path($imageFile));
     if ($crop) {
         $image->grab($width, $hegiht);
     } else {
         $image->resize($width, $hegiht, true);
     }
     if ($watermark) {
         if (!$watermark['sizes'] || in_array($sizeKey, $watermark['sizes'])) {
             $image->insert($watermark['image'], $watermark['offset'][0], $watermark['offset'][1], $watermark['position']);
         }
     }
     $tmpFile = public_path($model->{$field}) . '.tmp_' . uniqid();
     $newFile = public_path(Config::get('devhook.imageRoute') . '/' . implode('/', $args));
     $newPath = dirname($newFile);
     if (!File::exists($newPath)) {
         File::makeDirectory($newPath, 0777, true);
     }
     $image->save($newFile, $quality);
     $img = $image->encode($ext, $quality);
     $response = Response::make($img, 200);
     $response->header('Content-Type', 'image/jpeg');
     return $response;
 }
Esempio n. 20
0
 /**
  * Save a picture in the local filesystem.
  *
  * @param Picture $picture
  * @param string  $relativePath Relative to localDir
  *
  * @return boolean
  */
 private function savePictureLocally(Picture $picture, $relativePath)
 {
     $this->createLocalDirectory(dirname($relativePath));
     $result = $picture->save($this->localDataDirectory . $relativePath);
     clearstatcache();
     return $result;
 }