當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Imagick::flattenImages方法代碼示例

本文整理匯總了PHP中Imagick::flattenImages方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::flattenImages方法的具體用法?PHP Imagick::flattenImages怎麽用?PHP Imagick::flattenImages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Imagick的用法示例。


在下文中一共展示了Imagick::flattenImages方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: refresh

 /**
  * @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);
     }
 }
開發者ID:mgoldbeck,項目名稱:neos-development-collection,代碼行數:37,代碼來源:DocumentThumbnailGenerator.php

示例2: flatten

 /**
  * Internal
  *
  * Flatten the image.
  */
 private function flatten()
 {
     try {
         $this->imagick = $this->imagick->flattenImages();
     } catch (\ImagickException $e) {
         throw new RuntimeException('Flatten operation failed', $e->getCode(), $e);
     }
 }
開發者ID:kentonquatman,項目名稱:portfolio,代碼行數:13,代碼來源:Image.php

示例3: crop

 /**
  * Crops Image.
  *
  * @since 3.5.0
  * @access public
  *
  * @param string|int $src The source file or Attachment ID.
  * @param int $src_x The start x position to crop from.
  * @param int $src_y The start y position to crop from.
  * @param int $src_w The width to crop.
  * @param int $src_h The height to crop.
  * @param int $dst_w Optional. The destination width.
  * @param int $dst_h Optional. The destination height.
  * @param boolean $src_abs Optional. If the source crop points are absolute.
  * @return boolean|WP_Error
  */
 public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false)
 {
     $ar = $src_w / $src_h;
     $dst_ar = $dst_w / $dst_h;
     if (isset($_GET['pte-fit-crop-color']) && abs($ar - $dst_ar) > 0.01) {
         PteLogger::debug(sprintf("IMAGICK - AR: '%f'\tOAR: '%f'", $ar, $dst_ar));
         // Crop the image to the correct aspect ratio...
         if ($dst_ar > $ar) {
             // constrain to the dst_h
             $tmp_dst_h = $dst_h;
             $tmp_dst_w = $dst_h * $ar;
             $tmp_dst_y = 0;
             $tmp_dst_x = $dst_w / 2 - $tmp_dst_w / 2;
         } else {
             $tmp_dst_w = $dst_w;
             $tmp_dst_h = $dst_w / $ar;
             $tmp_dst_x = 0;
             $tmp_dst_y = $dst_h / 2 - $tmp_dst_h / 2;
         }
         //$color = this::getImagickPixel( $_GET['pte-fit-crop-color'] );
         if (preg_match("/^#[a-fA-F0-9]{6}\$/", $_GET['pte-fit-crop-color'])) {
             $color = new ImagickPixel($_GET['pte-fit-crop-color']);
         }
         //else {
         //    PteLogger::debug( "setting transparent/white" );
         //    $color = new ImagickPixel( 'white' );
         //    //$color->setColorValue( Imagick::COLOR_ALPHA, 0 );
         //}
         try {
             // crop the original image
             $this->image->cropImage($src_w, $src_h, $src_x, $src_y);
             $this->image->scaleImage($tmp_dst_w, $tmp_dst_h);
             // Create a new image and then compose the old one onto it.
             $img = new Imagick();
             $img->newImage($dst_w, $dst_h, isset($color) ? $color : 'white');
             $img->setImageFormat($this->image->getImageFormat());
             if (!isset($color)) {
                 $img->setImageOpacity(0.0);
             }
             $img->compositeImage($this->image, Imagick::COMPOSITE_DEFAULT, $tmp_dst_x, $tmp_dst_y);
             $img->flattenImages();
             $this->image = $img;
         } catch (Exception $e) {
             return new WP_Error('image_crop_error', __('Image crop failed.'), $this->file);
         }
         return $this->update_size();
     }
     return parent::crop($src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs);
 }
開發者ID:roycocup,項目名稱:enclothed,代碼行數:65,代碼來源:class-pte-image-editor-imagick.php

示例4: flatten

 /**
  * Internal
  *
  * Flatten the image.
  */
 private function flatten()
 {
     /**
      * @see https://github.com/mkoppanen/imagick/issues/45
      */
     try {
         if (method_exists($this->imagick, 'mergeImageLayers') && defined('Imagick::LAYERMETHOD_UNDEFINED')) {
             $this->imagick = $this->imagick->mergeImageLayers(\Imagick::LAYERMETHOD_UNDEFINED);
         } elseif (method_exists($this->imagick, 'flattenImages')) {
             $this->imagick = $this->imagick->flattenImages();
         }
     } catch (\ImagickException $e) {
         throw new RuntimeException('Flatten operation failed', $e->getCode(), $e);
     }
 }
開發者ID:scisahaha,項目名稱:generator-craft,代碼行數:20,代碼來源:Image.php

示例5: overlayImage

 /**
  * @see	\wcf\system\image\adapter\IImageAdapter::overlayImage()
  */
 public function overlayImage($file, $x, $y, $opacity)
 {
     try {
         $overlayImage = new \Imagick($file);
     } catch (\ImagickException $e) {
         throw new SystemException("Image '" . $file . "' is not readable or does not exist.");
     }
     $overlayImage->evaluateImage(\Imagick::EVALUATE_MULTIPLY, $opacity, \Imagick::CHANNEL_OPACITY);
     if ($this->imagick->getImageFormat() == 'GIF') {
         $this->imagick = $this->imagick->coalesceImages();
         do {
             $this->imagick->compositeImage($overlayImage, \Imagick::COMPOSITE_OVER, $x, $y);
         } while ($this->imagick->nextImage());
     } else {
         $this->imagick->compositeImage($overlayImage, \Imagick::COMPOSITE_OVER, $x, $y);
         $this->imagick = $this->imagick->flattenImages();
     }
 }
開發者ID:nick-strohm,項目名稱:WCF,代碼行數:21,代碼來源:ImagickImageAdapter.class.php

示例6: crop

 /**
  * Crops Image.
  *
  * @since 3.5.0
  * @access public
  *
  * @param string|int $src The source file or Attachment ID.
  * @param int $src_x The start x position to crop from.
  * @param int $src_y The start y position to crop from.
  * @param int $src_w The width to crop.
  * @param int $src_h The height to crop.
  * @param int $dst_w Optional. The destination width.
  * @param int $dst_h Optional. The destination height.
  * @param boolean $src_abs Optional. If the source crop points are absolute.
  * @return boolean|WP_Error
  */
 public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false)
 {
     if (pte_is_crop_border_enabled($src_w, $src_h, $dst_w, $dst_h)) {
         // Crop the image to the correct aspect ratio...
         $ar = $src_w / $src_h;
         $dst_ar = $dst_w / $dst_h;
         if ($dst_ar > $ar) {
             // constrain to the dst_h
             $tmp_dst_h = $dst_h;
             $tmp_dst_w = $dst_h * $ar;
             $tmp_dst_y = 0;
             $tmp_dst_x = $dst_w / 2 - $tmp_dst_w / 2;
         } else {
             $tmp_dst_w = $dst_w;
             $tmp_dst_h = $dst_w / $ar;
             $tmp_dst_x = 0;
             $tmp_dst_y = $dst_h / 2 - $tmp_dst_h / 2;
         }
         if (pte_is_crop_border_opaque()) {
             $color = new ImagickPixel($_GET['pte-fit-crop-color']);
         }
         try {
             // crop the original image
             $this->image->cropImage($src_w, $src_h, $src_x, $src_y);
             $this->image->scaleImage($tmp_dst_w, $tmp_dst_h);
             // Create a new image and then compose the old one onto it.
             $img = new Imagick();
             $img->newImage($dst_w, $dst_h, isset($color) ? $color : 'white');
             $img->setImageFormat($this->image->getImageFormat());
             if (!isset($color)) {
                 $img->setImageOpacity(0.0);
             }
             $img->compositeImage($this->image, Imagick::COMPOSITE_DEFAULT, $tmp_dst_x, $tmp_dst_y);
             $img->flattenImages();
             $this->image = $img;
         } catch (Exception $e) {
             return new WP_Error('image_crop_error', __('Image crop failed.'), $this->file);
         }
         return $this->update_size();
     }
     return parent::crop($src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs);
 }
開發者ID:ilke-zilci,項目名稱:newcomers-wp,代碼行數:58,代碼來源:class-pte-image-editor-imagick.php

示例7: paste

 /**
  * (non-PHPdoc)
  * @see Imagine\ImageInterface::paste()
  */
 public function paste(ImageInterface $image, PointInterface $start)
 {
     if (!$image instanceof self) {
         throw new InvalidArgumentException(sprintf('Imagick\\Image can ' . 'only paste() Imagick\\Image instances, %s given', get_class($image)));
     }
     if (!$this->getSize()->contains($image->getSize(), $start)) {
         throw new OutOfBoundsException('Cannot paste image of the given size at the specified ' . 'position, as it moves outside of the current image\'s box');
     }
     try {
         $this->imagick->compositeImage($image->imagick, \Imagick::COMPOSITE_DEFAULT, $start->getX(), $start->getY());
     } catch (\ImagickException $e) {
         throw new RuntimeException('Paste operation failed', $e->getCode(), $e);
     }
     try {
         $this->imagick->flattenImages();
     } catch (\ImagickException $e) {
         throw new RuntimeException('Paste operation failed', $e->getCode(), $e);
     }
     return $this;
 }
開發者ID:nicodmf,項目名稱:Imagine,代碼行數:24,代碼來源:Image.php

示例8: _prepare_image

 /**
  * Prepare the image for output, scaling and flattening as required
  *
  * @since 2.10
  * @uses self::$image updates the image in this Imagick object
  *
  * @param	integer	zero or new width
  * @param	integer	zero or new height
  * @param	boolean	proportional fit (true) or exact fit (false)
  * @param	string	output MIME type
  * @param	integer	compression quality; 1 - 100
  *
  * @return void
  */
 private static function _prepare_image($width, $height, $best_fit, $type, $quality)
 {
     if (is_callable(array(self::$image, 'scaleImage'))) {
         if (0 < $width && 0 < $height) {
             // Both are set; use them as-is
             self::$image->scaleImage($width, $height, $best_fit);
         } elseif (0 < $width || 0 < $height) {
             // One is set; scale the other one proportionally if reducing
             $image_size = self::$image->getImageGeometry();
             if ($width && isset($image_size['width']) && $width < $image_size['width']) {
                 self::$image->scaleImage($width, 0);
             } elseif ($height && isset($image_size['height']) && $height < $image_size['height']) {
                 self::$image->scaleImage(0, $height);
             }
         } else {
             // Neither is specified, apply defaults
             self::$image->scaleImage(150, 0);
         }
     }
     if (0 < $quality && 101 > $quality) {
         if ('image/jpeg' == $type) {
             self::$image->setImageCompressionQuality($quality);
             self::$image->setImageCompression(imagick::COMPRESSION_JPEG);
         } else {
             self::$image->setImageCompressionQuality($quality);
         }
     }
     if ('image/jpeg' == $type) {
         if (is_callable(array(self::$image, 'setImageBackgroundColor'))) {
             self::$image->setImageBackgroundColor('white');
         }
         if (is_callable(array(self::$image, 'mergeImageLayers'))) {
             self::$image = self::$image->mergeImageLayers(imagick::LAYERMETHOD_FLATTEN);
         } elseif (is_callable(array(self::$image, 'flattenImages'))) {
             self::$image = self::$image->flattenImages();
         }
     }
 }
開發者ID:axeljohansson1988,項目名稱:oddcv,代碼行數:52,代碼來源:class-mla-image-processor.php

示例9:

        $watermarkHeight = $watermark->getImageHeight();
        // Get original image sizes
        $imageWidth = $original->getImageWidth();
        $imageHeight = $original->getImageHeight();
        // Merge watermark in tiling mode
        for ($x = $initialX;; $x += $watermarkWidth + (int) $originY) {
            for ($y = $initialY;; $y += $watermarkHeight + (int) $originX) {
                $original->compositeImage($watermark, Imagick::COMPOSITE_DEFAULT, $x, $y);
                if ($y > $imageHeight) {
                    break;
                }
            }
            if ($x > $imageWidth) {
                break;
            }
        }
    } else {
        // Merge watermark in normal mode
        $original->compositeImage($watermark, Imagick::COMPOSITE_DEFAULT, $originX, $originY);
    }
    // Make flat image
    $original->flattenImages();
    // Make filename and filedir
    $file_name = make_filename($originalImagePath, 'png');
    $file_dir = get_download_filedir($file_name);
    // Save image
    $original->setImageFormat('png');
    $original->writeImage($file_dir);
    // Send image name to user
    send_filename($file_name);
}
開發者ID:6thSence,項目名稱:Generator-of-watermarks,代碼行數:31,代碼來源:download.php

示例10: _convert

 /**
  * Image conversion abstraction.
  *
  * @param string $source
  * @param array $size
  * @return Imagick
  */
 protected function _convert($source, $size)
 {
     extract($size);
     $im = new Imagick();
     $js = 0;
     $hint = max($tw, $th) * $js;
     if ($hint > 0 && $hint < $sw && $hint < $sh) {
         if (pathinfo($source, PATHINFO_EXTENSION) === 'jpg') {
             $im->setOption('jpeg:size', sprintf('%dx%d', $hint, $hint));
         }
     }
     $im->readImage($source);
     if ($im->getNumberImages() > 1) {
         $im->flattenImages();
     }
     $colorspace = $im->getImageColorSpace();
     if ($colorspace !== Imagick::COLORSPACE_RGB && $colorspace !== Imagick::COLORSPACE_SRGB) {
         $im->setImageColorSpace(Imagick::COLORSPACE_SRGB);
     }
     if ($im->getImageMatte()) {
         $im->setImageMatte(false);
     }
     if ($this->doesTrimming()) {
         $im->cropImage($sw, $sh, $sx, $sy);
     }
     if ($this->doesResampling()) {
         $im->resizeImage($tw, $th, Imagick::FILTER_LANCZOS, 0.9, true);
     }
     $im->stripImage();
     $degrees = $this->getRotation();
     if ($degrees) {
         $bgcolor = $this->getBgColor();
         $bg = sprintf('rgb(%d,%d,%d)', $bgcolor[0], $bgcolor[1], $bgcolor[2]);
         $im->rotateImage(new ImagickPixel($bg), $degrees);
     }
     if ($this->isPng()) {
         $im->setFormat('PNG');
     } else {
         $im->setFormat('JPEG');
         if ($this->getQuality()) {
             $im->setCompressionQuality($this->getQuality());
         }
     }
     return $im;
 }
開發者ID:xingskycn,項目名稱:p2-php,代碼行數:52,代碼來源:Imagick.php

示例11: createThumb

    private function createThumb($src, $dist, $new_w, $new_h, $resize_type, $watermark) {
        if (file_exists($dist)) {
            if (!is_writable($dist)) { return false; }
            unlink($dist);
        }
        
        if (!in_array($resize_type, array('exact', 'auto', 'crop', 'portrait', 'landscape'))) {
            $resize_type = 'auto';
        }
        
        if (!in_array($watermark, array('lt', 'lc', 'lb', 'rt', 'rc', 'rb', 'tc', 'c', 'bc')) && $watermark !== false) {
            $watermark = 'rb';
        }
        
        if ((int)$new_w) {
            if (
                ($this->w < $new_w && $this->h < $new_h) || 
                ($resize_type == 'portrait' && $this->h < $new_h) || 
                ($resize_type == 'landscape' && $this->w < $new_w)
            ) {
                copy($src, $dist);
            } else {
                $new_size = $this->getNewImageSize($new_w, $new_h, $resize_type);
                
                if ($this->Imagick === true) {
                    $image = new Imagick($src);
                    
                    switch ($resize_type) {
                        case 'auto':
                            if ($this->ext == 'gif'){
                                foreach ($image as $img) {
                                    $img->resizeImage($new_w, $new_h, Imagick::FILTER_LANCZOS, 1, true);
                                    $img->setImagePage($img->getImageWidth(), $img->getImageHeight(), 0, 0);
                                }
                            } else {
                                $image->resizeImage($new_w, $new_h, Imagick::FILTER_LANCZOS, 1, true);
                            }
                            
                            break;
                        case 'portrait':
                            if ($this->ext == 'gif'){
                                foreach ($image as $img) {
                                    $img->resizeImage(0, $new_h, Imagick::FILTER_LANCZOS, 1);
                                    $img->setImagePage($img->getImageWidth(), $img->getImageHeight(), 0, 0);
                                }
                            } else {
                                $image->resizeImage(0, $new_h, Imagick::FILTER_LANCZOS, 1);
                            }
                            break;
                        case 'landscape':
                            if ($this->ext == 'gif'){
                                foreach ($image as $img) {
                                    $img->resizeImage($new_w, 0, Imagick::FILTER_LANCZOS, 1);
                                    $img->setImagePage($img->getImageWidth(), $img->getImageHeight(), 0, 0);
                                }
                            } else {
                                $image->resizeImage($new_w, 0, Imagick::FILTER_LANCZOS, 1);
                            }
                            break;
                        case 'exact':
                            if ($this->ext == 'gif'){
                                foreach ($image as $img) {
                                    $img->resizeImage($new_w, $new_h, Imagick::FILTER_LANCZOS, 1);
                                    $img->setImagePage($img->getImageWidth(), $img->getImageHeight(), 0, 0);
                                }
                            } else {
                                $image->resizeImage($new_w, $new_h, Imagick::FILTER_LANCZOS, 1);
                            }
                            break;
                        case 'crop':
                            if ($this->ext == 'gif') {
                                foreach ($image as $img) {
                                    $img->cropThumbnailImage($new_w, $new_h);
                                    $img->setImagePage($img->getImageWidth(), $img->getImageHeight(), 0, 0);
                                }
                            } else {
                                $image->cropThumbnailImage($new_w, $new_h);
                            }
                            break;
                    }
                    
                    $image->setImageCompressionQuality($this->quality);
                    
                    if ($this->ext == 'jpg') {
                        $image->setImageBackgroundColor('white');
                        $image->flattenImages();
                        $image = $image->flattenImages();
                        $image->setImageCompression(Imagick::COMPRESSION_JPEG);
                    }
                    
                    $image->setImageFormat($this->ext);
                    
                    if ($this->ext == 'gif') {
                        $image->writeimages($dist);
                    } else {
                        $image->writeimage($dist);
                    }

                    $image->destroy();
                } else {
//.........這裏部分代碼省略.........
開發者ID:Acsac,項目名稱:CMS-RuDi,代碼行數:101,代碼來源:images.class.php

示例12: array

 function create_thumbnail($filename, $save2disk = true, $resize_type = 0)
 {
     $filename = $this->basename($filename);
     if ($this->is_image($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $filename) == true) {
         $extension = $this->file_extension($filename);
         $thumbnail = $this->thumbnail_name($filename);
         if ($save2disk == true) {
             // Seemed easier to build the image resize upload
             // option into the already established thumbnail function
             // instead of waisting time trying to chop it up for new one.
             if ($resize_type > 0 && $resize_type <= 8) {
                 $thumbnail = $filename;
                 $this->mmhclass->info->config['advanced_thumbnails'] = false;
                 $size_values = array(1 => array("w" => 100, "h" => 75), 2 => array("w" => 150, "h" => 112), 3 => array("w" => 320, "h" => 240), 4 => array("w" => 640, "h" => 480), 5 => array("w" => 800, "h" => 600), 6 => array("w" => 1024, "h" => 768), 7 => array("w" => 1280, "h" => 1024), 8 => array("w" => 1600, "h" => 1200));
                 $thumbnail_size = $size_values[$resize_type];
             } else {
                 $thumbnail_size = $this->scale($filename, $this->mmhclass->info->config['thumbnail_width'], $this->mmhclass->info->config['thumbnail_height']);
             }
             if ($this->manipulator == "imagick") {
                 // New Design of Advanced Thumbnails created by: IcyTexx - http://www.hostili.com
                 // Classic Design of Advanced Thumbnails created by: Mihalism Technologies - http://www.mihalism.net
                 $canvas = new Imagick();
                 $athumbnail = new Imagick();
                 $imagick_version = $canvas->getVersion();
                 // Imagick needs to start giving real version number, not build number.
                 $new_thumbnails = version_compare($imagick_version['versionNumber'], "1621", ">=") == true ? true : false;
                 $athumbnail->readImage("{$this->mmhclass->info->root_path}{$this->mmhclass->info->config['upload_path']}{$filename}[0]");
                 $athumbnail->flattenImages();
                 $athumbnail->orgImageHeight = $athumbnail->getImageHeight();
                 $athumbnail->orgImageWidth = $athumbnail->getImageWidth();
                 $athumbnail->orgImageSize = $athumbnail->getImageLength();
                 $athumbnail->thumbnailImage($thumbnail_size['w'], $thumbnail_size['h']);
                 if ($this->mmhclass->info->config['advanced_thumbnails'] == true) {
                     $thumbnail_filesize = $this->format_filesize($athumbnail->orgImageSize, true);
                     $resobar_filesize = $thumbnail_filesize['f'] < 0 || $thumbnail_filesize['c'] > 9 ? $this->mmhclass->lang['5454'] : sprintf("%s%s", round($thumbnail_filesize['f']), $this->mmhclass->lang['7071'][$thumbnail_filesize['c']]);
                     if ($new_thumbnails == true) {
                         $textdraw = new ImagickDraw();
                         $textdrawborder = new ImagickDraw();
                         if ($athumbnail->getImageWidth() > 113) {
                             $textdraw->setFillColor(new ImagickPixel("white"));
                             $textdraw->setFontSize(9);
                             $textdraw->setFont("{$mmhclass->info->root_path}css/fonts/sf_fedora_titles.ttf");
                             $textdraw->setFontWeight(900);
                             $textdraw->setGravity(8);
                             $textdraw->setTextKerning(1);
                             $textdraw->setTextAntialias(false);
                             $textdrawborder->setFillColor(new ImagickPixel("black"));
                             $textdrawborder->setFontSize(9);
                             $textdrawborder->setFont("{$mmhclass->info->root_path}css/fonts/sf_fedora_titles.ttf");
                             $textdrawborder->setFontWeight(900);
                             $textdrawborder->setGravity(8);
                             $textdrawborder->setTextKerning(1);
                             $textdrawborder->setTextAntialias(false);
                             $array_x = array("-1", "0", "1", "1", "1", "0", "-1", "-1");
                             $array_y = array("-1", "-1", "-1", "0", "1", "1", "1", "0");
                             foreach ($array_x as $key => $value) {
                                 $athumbnail->annotateImage($textdrawborder, $value, 3 - $array_y[$key], 0, "{$athumbnail->orgImageWidth}x{$athumbnail->orgImageHeight} - {$resobar_filesize}");
                             }
                             $athumbnail->annotateImage($textdraw, 0, 3, 0, "{}x{$athumbnail->orgImageHeight} - {$resobar_filesize}");
                         }
                     } else {
                         $transback = new Imagick();
                         $canvasdraw = new ImagickDraw();
                         $canvas->newImage($athumbnail->getImageWidth(), $athumbnail->getImageHeight() + 12, new ImagickPixel("black"));
                         $transback->newImage($canvas->getImageWidth(), $canvas->getImageHeight() - 12, new ImagickPixel("white"));
                         $canvas->compositeImage($transback, 40, 0, 0);
                         $canvasdraw->setFillColor(new ImagickPixel("white"));
                         $canvasdraw->setGravity(8);
                         $canvasdraw->setFontSize(10);
                         $canvasdraw->setFontWeight(900);
                         $canvasdraw->setFont("AvantGarde-Demi");
                         $canvas->annotateImage($canvasdraw, 0, 0, 0, "{$athumbnail->orgImageWidth}x{$athumbnail->orgImageHeight} - {$resobar_filesize}");
                         $canvas->compositeImage($athumbnail, 40, 0, 0);
                         $athumbnail = $canvas->clone();
                     }
                 }
                 if ($this->mmhclass->info->config['thumbnail_type'] == "jpeg") {
                     $athumbnail->setImageFormat("jpeg");
                     $athumbnail->setImageCompression(9);
                 } else {
                     $athumbnail->setImageFormat("png");
                 }
                 $athumbnail->writeImage($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $thumbnail);
             } else {
                 // I hate GD. Piece of crap supports nothing. NOTHING!
                 if (in_array($extension, array("png", "gif", "jpg", "jpeg")) == true) {
                     $function_extension = str_replace("jpg", "jpeg", $extension);
                     $image_function = "imagecreatefrom{$function_extension}";
                     $image = $image_function($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $filename);
                     $imageinfo = $this->get_image_info($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $this->basename($filename));
                     $thumbnail_image = imagecreatetruecolor($thumbnail_size['w'], $thumbnail_size['h']);
                     $index = imagecolortransparent($thumbnail_image);
                     if ($index < 0) {
                         $white = imagecolorallocate($thumbnail_image, 255, 255, 255);
                         imagefill($thumbnail_image, 0, 0, $white);
                     }
                     imagecopyresampled($thumbnail_image, $image, 0, 0, 0, 0, $thumbnail_size['w'], $thumbnail_size['h'], $imageinfo['width'], $imageinfo['height']);
                     $image_savefunction = sprintf("image%s", $this->mmhclass->info->config['thumbnail_type'] == "jpeg" ? "jpeg" : "png");
                     $image_savefunction($thumbnail_image, $this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $thumbnail);
                     chmod($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $thumbnail, 0644);
//.........這裏部分代碼省略.........
開發者ID:goXXip,項目名稱:mihalismmh,代碼行數:101,代碼來源:imagemagick.php

示例13: phorum_api_image_clip


//.........這裏部分代碼省略.........
        $clip_w = $image_info['width'] - $clip_x;
    }
    if (empty($clip_h)) {
        $clip_h = $image_info['height'] - $clip_y;
    }
    // The target image width and height are inherited from the clip
    // width and height, unless they are set.
    if (empty($dst_w)) {
        $dst_w = $clip_w;
    }
    if (empty($dst_h)) {
        $dst_h = $clip_h;
    }
    // Add the image data to the return array.
    $img['cur_w'] = $image_info['width'];
    $img['cur_h'] = $image_info['height'];
    $img['new_w'] = $dst_w;
    $img['new_h'] = $dst_h;
    $img['cur_mime'] = $img['new_mime'] = $image_info['mime'];
    // Check if the requested clip fits the source image size.
    if ($clip_x + $clip_w > $img['cur_w']) {
        return phorum_api_error(PHROM_ERRNO_ERROR, "The clip X offset {$clip_x} + clip width {$clip_w} exceeds " . "the source image width {$img['cur_w']}");
    }
    if ($clip_y + $clip_h > $img['cur_h']) {
        return phorum_api_error(PHROM_ERRNO_ERROR, "The clip Y offset {$clip_y} + clip height {$clip_h} exceeds " . "the source image height {$img['cur_h']}");
    }
    // -----------------------------------------------------------------
    // Try to use the imagick library tools
    // -----------------------------------------------------------------
    if (($method === NULL || $method == 'imagick') && extension_loaded('imagick') && class_exists('Imagick')) {
        $method = NULL;
        $imagick = new Imagick();
        $imagick->readImageBlob($image);
        $imagick->flattenImages();
        $tmp = new Imagick();
        $tmp->newPseudoImage($img['cur_w'], $img['cur_h'], 'xc:white');
        $tmp->compositeImage($imagick, imagick::COMPOSITE_OVER, 0, 0);
        $imagick = $tmp;
        $imagick->cropImage($clip_w, $clip_h, $clip_x, $clip_y);
        $imagick->thumbnailImage($dst_w, $dst_h, FALSE);
        $imagick->setImagePage($clip_w, $clip_h, 0, 0);
        $imagick->setFormat("jpg");
        $img['image'] = $imagick->getImagesBlob();
        $img['new_mime'] = 'image/jpeg';
        $img['method'] = 'imagick';
        return $img;
    }
    // -----------------------------------------------------------------
    // Try to use the GD library tools
    // -----------------------------------------------------------------
    if (($method === NULL || $method == 'gd') && extension_loaded('gd') && function_exists('gd_info')) {
        // We need gd_info() to check whether GD has the required
        // image support for the type of image that we are handling.
        $gd = gd_info();
        // We always need JPEG support for the scaled down image.
        if (empty($gd['JPG Support']) && empty($gd['JPEG Support'])) {
            $error = "GD: no JPEG support available for processing images";
        } elseif ($type == 'gif' && empty($gd['GIF Read Support']) || $type == 'jpeg' && (empty($gd['JPG Support']) && empty($gd['JPEG Support'])) || $type == 'png' && empty($gd['PNG Support'])) {
            $error = "GD: no support available for image type \"{$type}\"";
        } else {
            // Create a GD image handler based on the image data.
            // imagecreatefromstring() spawns PHP warnings if the file cannot
            // be processed. We do not care to see that in the event logging,
            // so if event logging is loaded, we suspend it here.
            // Instead, we catch error output and try to mangle it into a
            // usable error message.
開發者ID:samuell,項目名稱:Core,代碼行數:67,代碼來源:image.php

示例14: create_scaled_image

 protected function create_scaled_image($file_name, $options)
 {
     $file_path = $this->options['upload_dir'] . $file_name;
     $new_file_path = $options['upload_dir'] . $file_name;
     if (extension_loaded('imagick')) {
         // Special Postscript case
         if ($this->is_ps_file($file_name)) {
             try {
                 $im = new \Imagick($file_path);
                 $im->flattenImages();
                 $im->setImageFormat('png');
                 $file_name .= '.png';
                 $file_path .= '.png';
                 $new_file_path .= '.png';
                 $im->writeImage($file_path);
             } catch (\ImagickException $e) {
                 return false;
             }
         }
     }
     list($img_width, $img_height) = @getimagesize($file_path);
     if (!$img_width || !$img_height) {
         return false;
     }
     $scale = min($options['max_width'] / $img_width, $options['max_height'] / $img_height);
     if ($scale >= 1) {
         if ($file_path !== $new_file_path) {
             return copy($file_path, $new_file_path);
         }
         return true;
     }
     $new_width = $img_width * $scale;
     $new_height = $img_height * $scale;
     $new_img = @imagecreatetruecolor($new_width, $new_height);
     switch (strtolower(substr(strrchr($file_name, '.'), 1))) {
         case 'jpg':
         case 'jpeg':
             $src_img = @imagecreatefromjpeg($file_path);
             $write_image = 'imagejpeg';
             $image_quality = isset($options['jpeg_quality']) ? $options['jpeg_quality'] : 75;
             break;
         case 'gif':
             @imagecolortransparent($new_img, @imagecolorallocate($new_img, 0, 0, 0));
             $src_img = @imagecreatefromgif($file_path);
             $write_image = 'imagegif';
             $image_quality = null;
             break;
         case 'png':
             @imagecolortransparent($new_img, @imagecolorallocate($new_img, 0, 0, 0));
             @imagealphablending($new_img, false);
             @imagesavealpha($new_img, true);
             $src_img = @imagecreatefrompng($file_path);
             $write_image = 'imagepng';
             $image_quality = isset($options['png_quality']) ? $options['png_quality'] : 9;
             break;
         default:
             $src_img = null;
     }
     $success = $src_img && @imagecopyresampled($new_img, $src_img, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height) && $write_image($new_img, $new_file_path, $image_quality);
     // Free up memory (imagedestroy does not delete files):
     @imagedestroy($src_img);
     @imagedestroy($new_img);
     return $success;
 }
開發者ID:punkave,項目名稱:symfony2-file-uploader-bundle,代碼行數:64,代碼來源:UploadHandler.php


注:本文中的Imagick::flattenImages方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。