Exemple #1
1
 /**
  * @return string
  * @throws CM_Exception
  */
 public function getBlob()
 {
     $this->_imagick->setImageCompressionQuality($this->getCompressionQuality());
     try {
         if ($this->_getAnimationRequired($this->getFormat())) {
             $imageBlob = $this->_imagick->getImagesBlob();
         } else {
             $imageBlob = $this->_imagick->getImageBlob();
         }
     } catch (ImagickException $e) {
         throw new CM_Exception('Cannot get image blob', null, ['originalExceptionMessage' => $e->getMessage()]);
     }
     return $imageBlob;
 }
 function render()
 {
     //Example Imagick::stripImage
     $imagick = new \Imagick(realpath("../imagick/images/Biter_500.jpg"));
     $bytes = $imagick->getImageBlob();
     echo "Image byte size before stripping: " . strlen($bytes) . "<br/>";
     $imagick->stripImage();
     $bytes = $imagick->getImageBlob();
     echo "Image byte size after stripping: " . strlen($bytes) . "<br/>";
     //Example end
 }
Exemple #3
0
 public function renderImage()
 {
     //Create a ImagickDraw object to draw into.
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     //http://www.imagemagick.org/Usage/compose/#compose_terms
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor('white');
     $draw->setStrokeWidth(2);
     $draw->setFontSize(72);
     $draw->setStrokeOpacity(1);
     $draw->setStrokeColor($darkColor);
     $draw->setStrokeWidth(2);
     $draw->setFont("../fonts/CANDY.TTF");
     $draw->setFontSize(140);
     $draw->setFillColor('none');
     $draw->rectangle(0, 0, 1000, 300);
     $draw->setFillColor('white');
     $draw->annotation(50, 180, "Lorem Ipsum!");
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     $draw->composite(\Imagick::COMPOSITE_MULTIPLY, -500, -200, 2000, 600, $imagick);
     //Create an image object which the draw commands can be rendered into
     $imagick = new \Imagick();
     $imagick->newImage(1000, 300, "SteelBlue2");
     $imagick->setImageFormat("png");
     //Render the draw commands in the ImagickDraw object
     //into the image.
     $imagick->drawImage($draw);
     //Send the image to the browser
     header("Content-Type: image/png");
     echo $imagick->getImageBlob();
 }
 public function getAction($systemIdentifier, Request $request)
 {
     $width = $request->get('width');
     $height = $request->get('height');
     $system = $this->getDoctrine()->getRepository('KoalamonIncidentDashboardBundle:System')->findOneBy(['identifier' => $systemIdentifier, 'project' => $this->getProject()]);
     $webDir = $this->container->getParameter('assetic.write_to');
     if ($system->getImage() == "") {
         $imageName = $webDir . self::DEFAULT_IMAGE;
     } else {
         $imageName = $webDir . ScreenshotCommand::IMAGE_DIR . DIRECTORY_SEPARATOR . $system->getImage();
     }
     $image = new \Imagick($imageName);
     if ($height || $width) {
         if (!$height) {
             $ratio = $width / $image->getImageWidth();
             $height = $image->getImageHeight() * $ratio;
         }
         if (!$width) {
             $ratio = $height / $image->getImageHeight();
             $width = $image->getImageWidth() * $ratio;
         }
         $image->scaleImage($width, $height, true);
     }
     $headers = array('Content-Type' => 'image/png', 'Content-Disposition' => 'inline; filename="' . $imageName . '"');
     return new Response($image->getImageBlob(), 200, $headers);
 }
 /**
  * @param Thumbnail $thumbnail
  * @return void
  * @throws Exception\NoThumbnailAvailableException
  */
 public function refresh(Thumbnail $thumbnail)
 {
     try {
         $filenameWithoutExtension = pathinfo($thumbnail->getOriginalAsset()->getResource()->getFilename(), PATHINFO_FILENAME);
         $temporaryLocalCopyFilename = $thumbnail->getOriginalAsset()->getResource()->createTemporaryLocalCopy();
         $documentFile = sprintf(in_array($thumbnail->getOriginalAsset()->getResource()->getFileExtension(), $this->getOption('paginableDocuments')) ? '%s[0]' : '%s', $temporaryLocalCopyFilename);
         $width = $thumbnail->getConfigurationValue('width') ?: $thumbnail->getConfigurationValue('maximumWidth');
         $height = $thumbnail->getConfigurationValue('height') ?: $thumbnail->getConfigurationValue('maximumHeight');
         $im = new \Imagick();
         $im->setResolution($this->getOption('resolution'), $this->getOption('resolution'));
         $im->readImage($documentFile);
         $im->setImageFormat('png');
         $im->setImageBackgroundColor('white');
         $im->setImageCompose(\Imagick::COMPOSITE_OVER);
         $im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_RESET);
         $im->thumbnailImage($width, $height, true);
         $im->flattenImages();
         // Replace flattenImages in imagick 3.3.0
         // @see https://pecl.php.net/package/imagick/3.3.0RC2
         // $im->mergeImageLayers(\Imagick::LAYERMETHOD_MERGE);
         $resource = $this->resourceManager->importResourceFromContent($im->getImageBlob(), $filenameWithoutExtension . '.png');
         $im->destroy();
         $thumbnail->setResource($resource);
         $thumbnail->setWidth($width);
         $thumbnail->setHeight($height);
     } catch (\Exception $exception) {
         $filename = $thumbnail->getOriginalAsset()->getResource()->getFilename();
         $sha1 = $thumbnail->getOriginalAsset()->getResource()->getSha1();
         $message = sprintf('Unable to generate thumbnail for the given document (filename: %s, SHA1: %s)', $filename, $sha1);
         throw new Exception\NoThumbnailAvailableException($message, 1433109652, $exception);
     }
 }
Exemple #6
0
 /**
  * Associates the model with the file
  * @param string $filePath
  * @return boolean
  */
 public function setFile($filePath)
 {
     if (!file_exists($filePath)) {
         return false;
     }
     $info = getimagesize($filePath);
     $imageWidth = $info[0];
     $imageHeight = $info[1];
     $image = new Imagick();
     $image->readimage($filePath);
     $image->setResourceLimit(Imagick::RESOURCETYPE_MEMORY, 1);
     $maxSize = 1920;
     if ($imageWidth > $maxSize && $imageWidth > $imageHeight) {
         $image->thumbnailimage($maxSize, null);
     } elseif ($imageHeight > $maxSize && $imageHeight > $imageWidth) {
         $image->thumbnailimage(null, $maxSize);
     }
     $image->setCompression(Imagick::COMPRESSION_JPEG);
     $image->setCompressionQuality(80);
     $image->stripimage();
     $this->size = filesize($filePath);
     $this->type = $info['mime'];
     $this->width = $info[0];
     $this->height = $info[1];
     $this->content = $image->getImageBlob();
     $this->expireAt(time() + static::EXP_DAY);
     return true;
 }
 function renderOriginalImage()
 {
     $imagick = new \Imagick(realpath("./images/chair.jpeg"));
     header("Content-Type: image/jpg");
     echo $imagick->getImageBlob();
     return;
 }
 public function makeThumb($path, $W = NULL, $H = NULL)
 {
     $image = new Imagick();
     $image->readImage($ImgSrc);
     // Trasformo in RGB solo se e` il CMYK
     if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
         $image->transformImageColorspace(Imagick::COLORSPACE_RGB);
     }
     $image->profileImage('*', NULL);
     $image->stripImage();
     $imgWidth = $image->getImageWidth();
     $imgHeight = $image->getImageHeight();
     if ((!$H || $H == null || $H == 0) && (!$W || $W == null || $W == 0)) {
         $W = $imgWidth;
         $H = $imgHeight;
     } elseif (!$H || $H == null || $H == 0) {
         $H = $W * $imgHeight / $imgWidth;
     } elseif (!$W || $W == null || $W == 0) {
         $W = $H * $imgWidth / $imgHeight;
     }
     $image->resizeImage($W, $H, Imagick::FILTER_LANCZOS, 1);
     /** Scrivo l'immagine */
     $image->writeImage($path);
     /** IMAGE OUT */
     header('X-MHZ-FLY: Nice job!');
     header(sprintf('Content-type: image/%s', strtolower($image->getImageFormat())));
     echo $image->getImageBlob();
     $image->destroy();
     die;
 }
 /**
  * Displays image without saving and lose changes
  *
  * This method adds the Content-type HTTP header
  *
  * @param string type (JPG,PNG...);
  * @param int quality 75
  *
  * @return bool|PEAR_Error TRUE or a PEAR_Error object on error
  * @access public
  */
 function display($type = '', $quality = null)
 {
     $options = is_array($quality) ? $quality : array();
     if (is_numeric($quality)) {
         $options['quality'] = $quality;
     }
     $quality = $this->_getOption('quality', $options, 75);
     $this->imagick->setImageCompression($quality);
     if ($type && strcasecmp($type, $this->type)) {
         try {
             $this->imagick->setImageFormat($type);
         } catch (ImagickException $e) {
             return $this->raiseError('Could not save image to file (conversion failed).', IMAGE_TRANSFORM_ERROR_FAILED);
         }
     }
     try {
         $image = $this->imagick->getImageBlob();
     } catch (ImagickException $e) {
         return $this->raiseError('Could not display image.', IMAGE_TRANSFORM_ERROR_IO);
     }
     header('Content-type: ' . $this->getMimeType($type));
     echo $image;
     $this->free();
     return true;
 }
 public function renderOriginalImage()
 {
     $imagick = new \Imagick();
     header("Content-Type: image/jpg");
     echo $imagick->getImageBlob();
     return;
 }
Exemple #11
0
 /**
  * Update the model data if the image has been changed
  *
  * @param EventInterface $event The event instance
  */
 public function updateModel(EventInterface $event)
 {
     $image = $event->getArgument('image');
     if ($image->hasBeenTransformed()) {
         $image->setBlob($this->imagick->getImageBlob());
     }
 }
Exemple #12
0
function brightnessContrastImage($path_image, $brightness, $contrast, $channel)
{
    $imagick = new Imagick(realpath($path_image));
    $imagick->brightnessContrastImage($brightness, $contrast, $channel);
    header("Content-Type: image/jpeg");
    echo $imagick->getImageBlob();
}
 function _resize_image($image_path, $max_width = 100, $max_height = 100)
 {
     $imagick = new \Imagick(realpath($image_path));
     $imagick->thumbnailImage($max_width, $max_height, true);
     $blob = $imagick->getImageBlob();
     $imagick->clear();
     return $blob;
 }
Exemple #14
0
function thumbnailImage($imagePath)
{
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->setbackgroundcolor('rgb(64, 64, 64)');
    $imagick->thumbnailImage(300, 300, true, true);
    //header("Content-Type: image/jpg");
    return $imagick->getImageBlob();
}
Exemple #15
0
 public function getPng($resolutionX = 100, $resolutionY = 100)
 {
     $img = new \Imagick();
     $img->setResolution($resolutionX, $resolutionY);
     $img->readImageBlob($this->get());
     $img->setImageFormat('png');
     return $img->getImageBlob();
 }
Exemple #16
0
 public function raw($convert = false)
 {
     try {
         return $this->_imagick->getImageBlob();
     } catch (ImagickException $e) {
         throw Horde_Image_Exception($e);
     }
 }
Exemple #17
0
 public static function fromImagick(Imagick $im)
 {
     $i = new Image();
     $i->data = $im->getImageBlob();
     $i->mime = self::mimeToCode($im->getImageMimeType());
     $i->x = $im->getImageWidth();
     $i->y = $im->getImageHeight();
     return $i;
 }
Exemple #18
0
 /**
  *
  *    const GRAVITY_NORTHWEST = 1;
  * const GRAVITY_NORTH = 2;
  * const GRAVITY_NORTHEAST = 3;
  * const GRAVITY_WEST = 4;
  * const GRAVITY_CENTER = 5;
  * const GRAVITY_EAST = 6;
  * const GRAVITY_SOUTHWEST = 7;
  * const GRAVITY_SOUTH = 8;
  * const GRAVITY_SOUTHEAST = 9;
  */
 public function renderImage()
 {
     $imagick = new \Imagick(realpath("../imagick/images/Biter_500.jpg"));
     $imagick->setGravity(\Imagick::GRAVITY_SOUTHEAST);
     $imagick->cropImage(400, 300, 0, 0);
     $imagick->setimageformat('png');
     header("Content-Type: image/png");
     echo $imagick->getImageBlob();
 }
function createThumbnail($filename, $thname, $width = 100, $height = 100, $cdn = null)
{
    $filePath = 'pdfslice';
    try {
        $extension = substr($filename, strrpos($filename, '.') + 1 - strlen($filename));
        $fallback_save_path = $filePath;
        if ($extension == "svg") {
            $im = new Imagick();
            $svgdata = file_get_contents($filename);
            $svgdata = svgScaleHack($svgdata, $width, $height);
            //$im->setBackgroundColor(new ImagickPixel('transparent'));
            $im->readImageBlob($svgdata);
            $im->setImageFormat("jpg");
            $im->resizeImage($width, $height, imagick::FILTER_LANCZOS, 1);
            $raw_data = $im->getImageBlob();
            is_null($cdn) ? file_put_contents($fallback_save_path . '/' . $thname, $im->getImageBlob()) : '';
        } else {
            if ($extension == "jpg") {
                $im = new Imagick($filename);
                $im->stripImage();
                // Save as progressive JPEG
                $im->setInterlaceScheme(Imagick::INTERLACE_PLANE);
                $raw_data = $im->resizeImage($width, $height, imagick::FILTER_LANCZOS, 1);
                // Set quality
                // $im->setImageCompressionQuality(85);
                is_null($cdn) ? $im->writeImage($fallback_save_path . '/' . $thname) : '';
            }
        }
        if (!is_null($cdn)) {
            $imageObject = $cdn->DataObject();
            $imageObject->SetData($raw_data);
            $imageObject->name = $thname;
            $imageObject->content_type = 'image/jpg';
            $imageObject->Create();
        }
        $im->clear();
        $im->destroy();
        return true;
    } catch (Exception $e) {
        return false;
    }
}
 protected function _render($type, $quality)
 {
     $type = $this->_save_function($type, $quality);
     $this->im->setImageCompressionQuality($quality);
     $this->type = $type;
     $this->mime = image_type_to_mime_type($type);
     if ($this->im->getNumberImages() > 1 && $type == "gif") {
         return $this->im->getImagesBlob();
     }
     return $this->im->getImageBlob();
 }
 public static function openPdf($file)
 {
     if (!ImageServer::isEnabledPdf()) {
         return null;
     }
     $im = new Imagick($file . '[0]');
     $im->setImageFormat("png");
     $str = $im->getImageBlob();
     $im2 = imagecreatefromstring($str);
     return $im2;
 }
 public function processBinaryImageData(string $binaryImageData) : string
 {
     $this->validateImageDimensions($this->width, $this->height);
     $imagick = new \Imagick();
     try {
         $imagick->readImageBlob($binaryImageData);
     } catch (\ImagickException $e) {
         throw new InvalidBinaryImageDataException($e->getMessage());
     }
     $imagick->resizeImage($this->width, $this->height, \Imagick::FILTER_LANCZOS, 1);
     return $imagick->getImageBlob();
 }
 /**
  * {@inheritdoc}
  */
 public function getImageBlob($type = null, $quality = 95)
 {
     if ($type !== null) {
         if (!$this->image->setImageFormat($type)) {
             throw new RuntimeException(vsprintf("%s(): Unsupported image type [ %s ].", [__METHOD__, $type]));
         }
     }
     // Set image quality
     $this->image->setImageCompressionQuality($quality);
     // Return image blob
     return $this->image->getImageBlob();
 }
 /**
  * Get Thumbnail Response
  *
  * @param integer $width
  * @param Image   $image
  *
  * @return Response
  */
 public function getThumbnailResponse($width, $image)
 {
     if (!$image instanceof Image) {
         throw new \LogicException("Not a valid image");
     }
     $core = explode(";", $image->getContent());
     $content = base64_decode(substr($core[1], 7));
     $thumbnail = new \Imagick();
     $thumbnail->readImageBlob($content);
     $thumbnail->scaleImage($width, 0);
     return new Response($thumbnail->getImageBlob(), 200, array('Content-Type' => $image->getMimeType()));
 }
Exemple #25
0
 public function renderObject($shapes)
 {
     $imagick = new \Imagick();
     $imagick->newImage(500, 500, "#FFFFFF");
     $imagick->setImageFormat("png");
     foreach ($shapes as $shape) {
         $shape = CreateShape::generateObject($shape);
         if (!is_null($shape)) {
             $imagick->drawimage($shape);
         }
     }
     return $imagick->getImageBlob();
 }
Exemple #26
0
 /**
  * @return string
  * @throws CM_Exception
  */
 public function getBlob()
 {
     try {
         if ($this->_getAnimationRequired($this->getFormat())) {
             $imageBlob = $this->_imagick->getImagesBlob();
         } else {
             $imageBlob = $this->_imagick->getImageBlob();
         }
     } catch (ImagickException $e) {
         throw new CM_Exception('Cannot get image blob: ' . $e->getMessage());
     }
     return $imageBlob;
 }
Exemple #27
0
 public function renderOriginalImage()
 {
     $characterMethods = [\Imagick::MORPHOLOGY_CONVOLVE, \Imagick::MORPHOLOGY_ERODE_INTENSITY, \Imagick::MORPHOLOGY_DILATE_INTENSITY, \Imagick::MORPHOLOGY_OPEN_INTENSITY, \Imagick::MORPHOLOGY_CLOSE_INTENSITY];
     if (in_array($this->morphologyType, $characterMethods)) {
         $imagick = new \Imagick(realpath("./images/character.png"));
         header("Content-Type: image/png");
         echo $imagick->getImageBlob();
         return;
     }
     $canvas = $this->getCharacterOutline();
     header("Content-Type: image/png");
     echo $canvas->getImageBlob();
 }
Exemple #28
0
 function image($product_id = 0, $view = 'front', $index = 0)
 {
     $product_id = (int) $product_id;
     $index = (int) $index;
     if ($product_id == 0) {
         return false;
     }
     $this->load->driver('cache');
     if ($this->cache->file->get('product-img-' . $product_id . '-' . $view . '-' . $index) == false) {
         // load product design
         $this->load->model('product_m');
         $product = $this->product_m->getProductDesign($product_id);
         if (count($product)) {
             $this->load->helper('product');
             $help_product = new helperProduct();
             $design = $help_product->getDesign($product);
         } else {
             return false;
         }
         $design = json_decode(json_encode($design), true);
         if (empty($design[$view][$index])) {
             return false;
         }
         $string = str_replace("'", '"', $design[$view][$index]);
         $string = str_replace('px"', '"', $string);
         $img = new Imagick();
         $img->newImage(500, 500, new ImagickPixel('transparent'));
         $img->setImageFormat('png');
         $design = json_decode($string, true);
         $n = count($design) - 1;
         for ($i = $n; $i >= 0; $i--) {
             $image = $design[$i];
             if ($image['id'] == 'area-design') {
                 continue;
             }
             $file = ROOTPATH . DS . str_replace('/', DS, $image['img']);
             $newfile = new Imagick($file);
             $newfile->resizeImage($image['width'], $image['height'], Imagick::FILTER_LANCZOS, 1);
             $img->compositeImage($newfile, Imagick::COMPOSITE_DEFAULT, $image['left'], $image['top']);
         }
         $thumbnail = $img->getImageBlob();
         $this->cache->file->save('product-img-' . $product_id . '-' . $view . '-' . $index, base64_encode($thumbnail), 300000);
     } else {
         $img = $this->cache->file->get('product-img-' . $product_id . '-' . $view . '-' . $index);
         $thumbnail = base64_decode($img);
     }
     header("Content-Type: image/png");
     echo $thumbnail;
 }
Exemple #29
0
 /**
  * Get image data from image object
  * @param \Imagick $img
  * @param string $type
  * @return string mixed
  */
 private static function image2data($img, $type = 'png')
 {
     $img->setImageFormat($type);
     if ($img->getImageWidth() * $img->getImageHeight() > 40000) {
         switch ($type) {
             case 'png':
                 $img->setInterlaceScheme(\imagick::INTERLACE_PNG);
                 break;
             case 'jpeg':
                 $img->setInterlaceScheme(\imagick::INTERLACE_JPEG);
                 break;
         }
     }
     return $img->getImageBlob();
 }
 function renderCustomImage()
 {
     $size = 400;
     $imagick1 = new \Imagick();
     //$imagick1->newPseudoImage($size, $size, 'gradient:black-white');
     $imagick1->setColorspace(\Imagick::COLORSPACE_GRAY);
     //$imagick1->setColorspace(\Imagick::COLORSPACE_RGB);
     //$imagick1->setColorspace(\Imagick::COLORSPACE_SRGB);
     $imagick1->setColorspace(\Imagick::COLORSPACE_CMYK);
     $imagick1->newPseudoImage($size, $size, 'gradient:gray(100%)-gray(0%)');
     $imagick1->setFormat('png');
     //analyzeImage($imagick1);
     header("Content-Type: image/png");
     echo $imagick1->getImageBlob();
 }