public function save($image = null, $options = array()) { $opts = array_merge(array('prefix' => '', 'basename' => uniqid(), 'uploadpath' => 'uncategorized', 'quality' => 85), $options); // Image processing library $imagine = new Imagine(); try { // Load image data $img = $imagine->load($image); $imgInfo = $img->getImagick()->identifyImage(); $format = explode(' ', $imgInfo['format']); $type = strtolower(reset($format)); // Uploaded file is an image if ($extension = $this->fileExtentionFromType($type, true)) { // Create roman (alpha-numeric, _) slug of company name, crude but effective $filename = $opts['prefix'] . $this->safeTransliterate($opts['basename']) . $extension; $filePath = $this->uploadPath . $opts['uploadpath'] . $filename; $img_max_width = $opts['max_width']; $img_max_height = $opts['max_height']; // Get image dimensions from Imagick handle $imgSize = $img->getSize(); $width = $imgSize->getWidth(); $height = $imgSize->getHeight(); // Is image larger than max values? if ($width > $img_max_width || $height > $img_max_height) { if ($width > $img_max_width && $height > $img_max_height) { // width and height is larger if ($width > $height) { try { $img = $img->resize($img->getSize()->widen($img_max_width)); } catch (Exception $e) { die($e->getMessage()); } } else { try { $img = $img->resize($img->getSize()->heighten($img_max_height)); } catch (Exception $e) { die($e->getMessage()); } } } else { if ($width > $img_max_width) { // width is larger try { $img = $img->resize($img->getSize()->widen($img_max_width)); } catch (Exception $e) { die($e->getMessage()); } } else { // height is larger try { $img = $img->resize($img->getSize()->heighten($img_max_height)); } catch (Exception $e) { die($e->getMessage()); } } } } // Save file try { echo $filePath; $img->save($filePath, array('quality' => $opts['quality'])); // Populate company_log field with absolute URL return $opts['uploadpath'] . $filename; } catch (Exception $e) { die($e->getMessage()); unset($data['company_logo']); } } } catch (Exception $e) { die($e->getMessage()); } }
/** * @param string $fileKey * @param string $fileKeyWithFormat * @param Format $format * * @return */ protected function generateThumbnail($fileKey, $fileKeyWithFormat, Format $format) { // check if has original picture try { $has = $this->fileSystem->has($fileKey); } catch (\OutOfBoundsException $e) { $has = false; } if (!$has) { throw new Exception\ImageDoesNotExistException(); } // create thumbnail try { $blobOriginal = $this->fileSystem->read($fileKey); } catch (FileNotFound $e) { throw new Exception\ImageDoesNotExistException(); } $imagine = new Imagine(); $image = $imagine->load($blobOriginal); $resizedImage = Manipulator::resize($image, $format); $extension = $this->getExtension($fileKey); $blobResizedImage = $resizedImage->get($extension, array('jpeg_quality' => 90, 'png_compression_level' => 9)); $this->fileSystem->write($fileKeyWithFormat, $blobResizedImage, true); return $blobResizedImage; }
/** * Create a new ImageInterface instance form the given binary string. * * @param string $string Binary string that holds image information. * * @return \Webiny\Component\Image\ImageInterface */ public function load($string) { return new Image($this->instance->load($string)); }
/** * Opens image with Imagine Imagick * * @return AbstractImage */ protected function loadWithImagick() { $imagine = new ImagickImage(); return $imagine->load($this->image); }
public static function read($resource) { $adapter = new Imagine(); return $adapter->load($resource); }
function prepare() { $imagine = new Imagine(); $this->image = $imagine->load($this->data); }