示例#1
1
 function mkbilder()
 {
     $this->err->write('mkbilder', 'IN');
     if (!class_exists("Imagick")) {
         $this->err->out("Imagick-Extention nicht installiert", true);
         return false;
     }
     $handle = new Imagick();
     if (!$handle->readImage("./tmp/tmp.file_org")) {
         return false;
     }
     $d = $handle->getImageGeometry();
     if ($d["width"] < $d["height"]) {
         $faktor = $d["height"] / $d["width"];
     } else {
         $faktor = $d["width"] / $d["height"];
     }
     $thumbheight = floor($this->thumbwidth * $faktor);
     $handle->thumbnailImage($this->thumbwidth, $thumbheight);
     $rc = $handle->writeImage("./tmp/tmp.file_thumb");
     $handle->readImage("./tmp/tmp.file_org");
     $popupheight = floor($this->popupwidth * $faktor);
     $handle->thumbnailImage($this->popupwidth, $popupheight);
     $rc = $handle->writeImage("./tmp/tmp.file_popup");
     $handle->readImage("./tmp/tmp.file_org");
     $infoheight = floor($this->infowidth * $faktor);
     $handle->thumbnailImage($this->infowidth, $infoheight);
     $rc = $handle->writeImage("./tmp/tmp.file_info");
     return $rc;
 }
示例#2
0
 function imagick_thumbnail($image, $timage, $ext, $thumbnail_name, $imginfo)
 {
     try {
         $imagick = new Imagick();
         $fullpath = "./" . $this->thumbnail_path . "/" . $timage[0] . "/" . $thumbnail_name;
         if ($ext == "gif") {
             $imagick->readImage($image . '[0]');
         } else {
             $imagick->readImage($image);
         }
         $info = $imagick->getImageGeometry();
         $this->info[0] = $info['width'];
         $this->info[1] = $info['height'];
         $imagick->thumbnailImage($this->dimension, $this->dimension, true);
         if ($ext == "png" || $ext == "gif") {
             $white = new Imagick();
             $white->newImage($this->dimension, $this->dimension, "white");
             $white->compositeimage($image, Imagick::COMPOSITE_OVER, 0, 0);
             $white->writeImage($fullpath);
             $white->clear();
         } else {
             $imagick->writeImage($fullpath);
         }
         $imagick->clear();
     } catch (Exception $e) {
         echo "Unable to load image." . $e->getMessage();
         return false;
     }
     return true;
 }
示例#3
0
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $mimetype = $fileview->getMimeType($path);
     $path = \OC_Helper::mimetypeIcon($mimetype);
     $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT));
     $svgPath = substr_replace($path, 'svg', -3);
     if (extension_loaded('imagick') && file_exists($svgPath) && count(@\Imagick::queryFormats("SVG")) === 1) {
         // http://www.php.net/manual/de/imagick.setresolution.php#85284
         $svg = new \Imagick();
         $svg->readImage($svgPath);
         $res = $svg->getImageResolution();
         $x_ratio = $res['x'] / $svg->getImageWidth();
         $y_ratio = $res['y'] / $svg->getImageHeight();
         $svg->removeImage();
         $svg->setResolution($maxX * $x_ratio, $maxY * $y_ratio);
         $svg->setBackgroundColor(new \ImagickPixel('transparent'));
         $svg->readImage($svgPath);
         $svg->setImageFormat('png32');
         $image = new \OC_Image();
         $image->loadFromData($svg);
     } else {
         $image = new \OC_Image($path);
     }
     return $image;
 }
 public function __construct($file)
 {
     if (!self::$checked) {
         self::check();
     }
     parent::__construct($file);
     $this->im = new Imagick();
     $this->im->readImage($file);
 }
 /**
  * @see	\wcf\system\image\adapter\IImageAdapter::loadFile()
  */
 public function loadFile($file)
 {
     try {
         $this->imagick->clear();
         $this->imagick->readImage($file);
     } catch (\ImagickException $e) {
         throw new SystemException("Image '" . $file . "' is not readable or does not exist.");
     }
     $this->readImageDimensions();
 }
 /**
  * @see	wcf\system\image\adapter\IImageAdapter::loadFile()
  */
 public function loadFile($file)
 {
     try {
         $this->imagick->readImage($file);
     } catch (\ImagickException $e) {
         throw new SystemException("Image '" . $file . "' is not readable or does not exist.");
     }
     $this->height = $this->imagick->getImageHeight();
     $this->width = $this->imagick->getImageWidth();
 }
示例#7
0
 /**
  * Open the image.
  * @param string $filename
  * @param boolean $throwErrors
  * @throws InvalidParamException
  * @throws \ErrorException
  */
 public function __construct($filename, $throwErrors = true)
 {
     static $isLoaded;
     if (!isset($isLoaded)) {
         $isLoaded = self::isLoaded();
     }
     parent::__construct($filename, $throwErrors);
     $this->im = new \Imagick();
     $this->im->readImage($this->filename);
     if (!$this->im->getImageAlphaChannel()) {
         $this->im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_SET);
     }
 }
 function load($file_name, $type = '')
 {
     $this->destroyImage();
     $imginfo = @getimagesize($file_name);
     if (!$imginfo) {
         throw new lmbFileNotFoundException($file_name);
     }
     $this->img = new Imagick();
     $this->img->readImage($file_name);
     if (!$this->img instanceof Imagick) {
         throw new lmbImageCreateFailedException($file_name);
     }
     $this->img_type = $this->img->getImageFormat();
 }
 /**
  * {@inheritDoc}
  */
 public function apply($absolutePath)
 {
     $info = pathinfo($absolutePath);
     if (isset($info['extension']) && false !== strpos(strtolower($info['extension']), 'pdf')) {
         // If it doesn't exists, extract the first page of the PDF
         if (!file_exists("{$absolutePath}.png")) {
             $this->imagick->readImage($absolutePath . '[0]');
             $this->imagick->setImageFormat('png');
             $this->imagick->writeImage("{$absolutePath}.png");
             $this->imagick->clear();
         }
         $absolutePath .= '.png';
     }
     return $absolutePath;
 }
示例#10
0
 /**
  * Creates a thumbnail with imagick.
  *
  * @param  File    $fileObject           FileObject to add properties
  * @param  string  $httpPathToMediaDir   Http path to file
  * @param  string  $pathToMediaDirectory Local path to file
  * @param  string  $fileName             Name of the image
  * @param  string  $fileExtension        Fileextension
  * @param  integer $width                Width of thumbnail, if omitted, size will be proportional to height
  * @param  integer $height               Height of thumbnail, if omitted, size will be proportional to width
  *
  * @throws ThumbnailCreationFailedException              If imagick is not supported
  * @throws InvalidArgumentException      If both, height and width are omitted or file format is not supported
  */
 private static function createThumbnailWithImagick(File &$fileObject, $httpPathToMediaDir, $pathToMediaDirectory, $fileName, $fileExtension, $width = null, $height = null)
 {
     if (!extension_loaded('imagick')) {
         throw new ExtensionNotLoadedException('Imagick is not loaded on this system');
     }
     if ($width === null && $height === null) {
         throw new InvalidArgumentException('Either width or height must be provided');
     }
     // create thumbnails with imagick
     $imagick = new \Imagick();
     if (!in_array($fileExtension, $imagick->queryFormats("*"))) {
         throw new ThumbnailCreationFailedException('No thumbnail could be created for the file format');
     }
     // read image into imagick
     $imagick->readImage(sprintf('%s/%s.%s', $pathToMediaDirectory, $fileName, $fileExtension));
     // set size
     $imagick->thumbnailImage($width, $height);
     // null values allowed
     // write image
     $imagick->writeImage(sprintf('%s/%sx%s-thumbnail-%s.%s', $pathToMediaDirectory, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     $fileObject->setThumbnailLink(sprintf('%s/%sx%s-thumbnail-%s.%s', $httpPathToMediaDir, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     $fileObject->setLocalThumbnailPath(sprintf('%s/%sx%s-thumbnail-%s.%s', $pathToMediaDirectory, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     // free up associated resources
     $imagick->destroy();
 }
 /**
  * @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);
     }
 }
示例#12
0
文件: Common.php 项目: fooman/tcpdf
 protected function _pdfPageToImage($input, $page)
 {
     $path = $input . '[' . $page . ']';
     $image = new \Imagick();
     $image->readImage($path);
     return $image;
 }
 public function addWatermark($image_path)
 {
     try {
         // Open the original image
         $image = new \Imagick();
         $is_success = $image->readImage($image_path);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot read uploaded image");
         }
         $watermark = new \Imagick();
         $is_success = $watermark->readImage($this->_WATERMARK_IMAGE_PATH);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot read uploaded image");
         }
         $image_width = $image->getImageWidth();
         $image_height = $image->getImageHeight();
         $watermark_width = $watermark->getImageWidth();
         $watermark_height = $watermark->getImageHeight();
         $watermark_pos_x = $image_width - $watermark_width - 20;
         $watermark_pos_y = 20;
         // Overlay the watermark on the original image
         $is_success = $image->compositeImage($watermark, \imagick::COMPOSITE_OVER, $watermark_pos_x, $watermark_pos_y);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot save image after watermarked");
         }
         //Write the image
         $image->writeImage($image_path);
     } catch (ImagickException $e) {
         error_log($e->getMessage());
         throw new WatermarkException($e->getMessage(), $e->getCode(), $e);
     }
 }
 /**
  * @param string      $path
  * @param null|string $name
  *
  * @throws ProcessorException
  *
  * @returns $this
  */
 public function readFile($path, $name = null)
 {
     if (true !== is_readable($path)) {
         throw new ProcessorException('File path is not readable: %s', null, null, (string) $path);
     }
     if (null === $name || strlen($name) === 0) {
         $name = pathinfo($path, PATHINFO_FILENAME);
     }
     $this->initialize(true);
     try {
         $this->im->readImage($path);
     } catch (\Exception $e) {
         throw new ProcessorException('Could not read image %s from path %s: %s', null, $e, (string) $name, (string) $path, (string) $e->getMessage());
     }
     return $this;
 }
示例#15
0
 /**
  * @param  $width
  * @param  $height
  * @return self
  */
 public function resize($width, $height)
 {
     $this->preModify();
     // this is the check for vector formats because they need to have a resolution set
     // this does only work if "resize" is the first step in the image-pipeline
     if ($this->isVectorGraphic()) {
         // the resolution has to be set before loading the image, that's why we have to destroy the instance and load it again
         $res = $this->resource->getImageResolution();
         $x_ratio = $res['x'] / $this->getWidth();
         $y_ratio = $res['y'] / $this->getHeight();
         $this->resource->removeImage();
         $newRes = ["x" => $width * $x_ratio, "y" => $height * $y_ratio];
         // only use the calculated resolution if we need a higher one that the one we got from the metadata (getImageResolution)
         // this is because sometimes the quality is much better when using the "native" resulution from the metadata
         if ($newRes["x"] > $res["x"] && $newRes["y"] > $res["y"]) {
             $this->resource->setResolution($newRes["x"], $newRes["y"]);
         } else {
             $this->resource->setResolution($res["x"], $res["y"]);
         }
         $this->resource->readImage($this->imagePath);
         $this->setColorspaceToRGB();
     }
     $width = (int) $width;
     $height = (int) $height;
     $this->resource->resizeimage($width, $height, \Imagick::FILTER_UNDEFINED, 1, false);
     $this->setWidth($width);
     $this->setHeight($height);
     $this->postModify();
     return $this;
 }
 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;
 }
 function getPage($page)
 {
     $format = $this->parameters['format_image'];
     switch ($format) {
         case "imagick":
         case "png":
             $extension = "png";
             $content_type = "image/x-png";
             break;
         case "jpeg":
             $extension = "jpg";
             $content_type = "image/jpeg";
             break;
     }
     $len = strlen($this->getPageCount());
     if (!file_exists($this->doc->driver->get_cached_filename($this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . "." . $extension)) {
         $resolution = $this->parameters['resolution_image'];
         if ($format == "imagick") {
             exec("pdftoppm -f {$page} -l {$page} -r " . $resolution . " " . $this->doc->driver->get_cached_filename($this->doc->id) . " " . $this->doc->driver->get_cached_filename("page_" . $this->doc->id));
             $imagick = new Imagick();
             $imagick->setResolution($resolution, $resolution);
             $imagick->readImage($this->doc->driver->get_cached_filename("page_" . $this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . ".ppm");
             $imagick->writeImage($this->doc->driver->get_cached_filename("page_" . $this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . ".png");
             unlink($this->doc->driver->get_cached_filename("page_" . $this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . ".ppm");
         } else {
             exec("pdftoppm -f {$page} -l {$page} -r " . $resolution . " -" . $format . " " . $this->doc->driver->get_cached_filename($this->doc->id) . " " . $this->doc->driver->get_cached_filename("page_" . $this->doc->id));
         }
     }
     if (file_exists($this->doc->driver->get_cached_filename("page_" . $this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . "." . $extension)) {
         header("Content-Type: " . $content_type);
         print file_get_contents($this->doc->driver->get_cached_filename("page_" . $this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . "." . $extension);
     }
 }
    function __construct($filename)
    {

        try {

            if(extension_loaded('imagick')) {
                $im = new Imagick();
                $im->readImage($filename);
                $width = $im->getImageWidth();
                $height = $im->getImageHeight();
                $source = new \Zxing\IMagickLuminanceSource($im, $width, $height);
            }else {
                $image = file_get_contents($filename);
                $sizes = getimagesize($filename);
                $width = $sizes[0];
                $height = $sizes[1];
                $im = imagecreatefromstring($image);

                $source = new \Zxing\GDLuminanceSource($im, $width, $height);
            }
            $histo = new Zxing\Common\HybridBinarizer($source);
            $bitmap = new Zxing\BinaryBitmap($histo);
            $reader = new Zxing\Qrcode\QRCodeReader();

            $this->result = $reader->decode($bitmap);
        }catch (\Zxing\NotFoundException $er){
            $this->result = false;
        }catch( \Zxing\FormatException $er){
            $this->result = false;
        }catch( \Zxing\ChecksumException $er){
            $this->result = false;
        }
    }
示例#19
0
 /**
  * 
  * 
  * 
  * Data comes in following format
  * 
  * array(
  *         <fileId>  =>  <pdfFilePath>
  *      );
  * 
  * @param type $data
  * @return int
  */
 public function createThumbnails($data)
 {
     return NULL;
     if (!extension_loaded('imagick')) {
     }
     //die();
     $imagick = new \Imagick();
     foreach ($data as $fileId => $filePath) {
         if (is_file($filePath)) {
             dump($filePath . ' exists');
         }
     }
     die;
     if (!file_exists($pdfName)) {
         return 0;
     }
     $pdf = new \Imagick();
     $pdf->readImage($pdfName);
     $pages = count($pdf);
     $pages = $pages ? $pages + 1 : 0;
     foreach ($pdf as $index => $image) {
         $image->setcolorspace(\Imagick::COLORSPACE_RGB);
         $image->setCompression(\Imagick::COMPRESSION_JPEG);
         $image->setCompressionQuality(90);
         $image->setResolution(600, 600);
         $image->setImageFormat('jpeg');
         //  $image->resizeImage(405, 574, \Imagick::FILTER_LANCZOS, 1 , TRUE);
         $image->writeImage($folder . '/' . ($index + 1) . '.jpg');
     }
     $pdf->destroy();
     $pages = count(glob($folder . '/*.jpg'));
     return $pages;
 }
示例#20
0
function addCrest($s, $fileName, $offset)
{
    print "{$fileName}\n";
    $slot = new Imagick();
    $slot->readImage($fileName);
    $s->compositeImage($slot, $slot->getImageCompose(), 0, $offset);
    $slot->destroy();
}
 /**
  * Apply the transformer on the absolute path and return an altered version of it.
  *
  * @param string $absolutePath
  *
  * @return string|false
  */
 public function apply($absolutePath)
 {
     $info = pathinfo($absolutePath);
     if (isset($info['extension']) && false !== strpos(strtolower($info['extension']), 'pdf') && file_exists($absolutePath)) {
         // If it doesn't exist yet, extract the first page of the PDF
         $previewFilename = $this->getPreviewFilename($absolutePath);
         if (!file_exists($previewFilename)) {
             $this->imagick->readImage($absolutePath . '[0]');
             $this->imagick->setImageFormat('jpg');
             $this->imagick->flattenimages();
             $this->imagick->writeImage($previewFilename);
             $this->imagick->clear();
         }
         $absolutePath = $previewFilename;
     }
     return $absolutePath;
 }
示例#22
0
 /**
  * {@inheritDoc}
  *
  * @return Imagick
  */
 public static function createFromFile($filename)
 {
     $imagick = new \Imagick();
     if ($imagick->readImage($filename) !== true) {
         throw new ImageException("The image file '{$filename}' cannot be loaded");
     }
     return new static($imagick);
 }
 public function run($file, $temp_dir)
 {
     $image = new Imagick();
     $image->readImage($file);
     $image->unsharpMaskImage($this->settings['radius'], $this->settings['sigma'], $this->settings['amount'], $this->settings['threshold']);
     $image->writeImage($file);
     return TRUE;
 }
 public function run($file, $temp_dir)
 {
     $image = new Imagick();
     $image->readImage($file);
     $image->sharpenImage($this->settings['radius'], $this->settings['sigma']);
     $image->writeImage($file);
     return TRUE;
 }
示例#25
0
 /**
  * @return ImageMagick
  */
 protected function initResource()
 {
     if (null === $this->resource) {
         $this->resource = new \Imagick();
     }
     $this->resource->readImage($this->imagePath);
     $this->setWidth($this->resource->getImageWidth())->setHeight($this->resource->getImageHeight());
     return $this;
 }
 function apply(lmbAbstractImageContainer $container)
 {
     $width = $container->getWidth();
     $height = $container->getHeight();
     $wm_cont = new Imagick();
     $wm_cont->readImage($this->getWaterMark());
     list($x, $y) = $this->calcPosition($this->getX(), $this->getY(), $width, $height);
     $container->getResource()->compositeImage($wm_cont, Imagick::COMPOSITE_OVER, $x, $y, Imagick::CHANNEL_ALL);
 }
示例#27
0
 /**
  * Contructor
  *
  * @param string $filename The path of ico file
  */
 public function __construct($filename)
 {
     if (!extension_loaded('imagick')) {
         throw new \Exception('IconExtractor needs imagick extension');
     }
     $image = new \Imagick();
     $image->readImage($filename);
     $this->image = $image;
 }
 public function readResource(ImThumbMeta $meta, ImThumb $requestor)
 {
     if (!$meta->valid) {
         return null;
     }
     $target = new Imagick();
     $target->readImage($meta->src);
     return $target;
 }
示例#29
0
 /**
  * 处理图片,不改变分辨率,减少图片文件大小
  * @param  [string] $src  原图路径
  * @param  [int] [图片质量]
  * @param  [string] $dest 目标图路径
  * @return [void] 
  */
 public function tinyJpeg($src, $quality = 60, $dest)
 {
     $img = new Imagick();
     $img->readImage($src);
     $img->setImageCompression(Imagick::COMPRESSION_JPEG);
     $img->setImageCompressionQuality($quality);
     $img->stripImage();
     $img->writeImage($dest);
     $img->clear();
 }
示例#30
0
 public function convert(string $file, Conversion $conversion = null) : string
 {
     $imageFile = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME) . '.jpg';
     $image = new \Imagick();
     $image->readImage($file);
     $image->setBackgroundColor(new ImagickPixel('none'));
     $image->setImageFormat('jpg');
     file_put_contents($imageFile, $image);
     return $imageFile;
 }