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


PHP Imagick::setImageDelay方法代碼示例

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


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

示例1: animate

 /**
  * {@inheritdoc}
  */
 public function animate($format, $delay, $loops)
 {
     if ('gif' !== strtolower($format)) {
         throw new InvalidArgumentException('Animated picture is currently only supported on gif');
     }
     if (!is_int($loops) || $loops < 0) {
         throw new InvalidArgumentException('Loops must be a positive integer.');
     }
     if (null !== $delay && (!is_int($delay) || $delay < 0)) {
         throw new InvalidArgumentException('Delay must be either null or a positive integer.');
     }
     try {
         foreach ($this as $offset => $layer) {
             $this->resource->setIteratorIndex($offset);
             $this->resource->setFormat($format);
             if (null !== $delay) {
                 $this->resource->setImageDelay($delay / 10);
                 $this->resource->setImageTicksPerSecond(100);
             }
             $this->resource->setImageIterations($loops);
             $this->resource->setImage($layer->getImagick());
         }
     } catch (\ImagickException $e) {
         throw new RuntimeException('Failed to animate layers', $e->getCode(), $e);
     }
     return $this;
 }
開發者ID:mm999,項目名稱:EduSoho,代碼行數:30,代碼來源:Layers.php

示例2: createAnimation

 /**
  * Generate the animated gif
  *
  * @return string binary image data
  */
 private function createAnimation($images)
 {
     $animation = new \Imagick();
     $animation->setFormat('gif');
     foreach ($images as $image) {
         $frame = new \Imagick();
         $frame->readImageBlob($image);
         $animation->addImage($frame);
         $animation->setImageDelay(50);
     }
     return $animation->getImagesBlob();
 }
開發者ID:renus,項目名稱:media,代碼行數:17,代碼來源:Video.php

示例3: animate

 /**
  * {@inheritdoc}
  */
 public function animate($format, $delay, $loops)
 {
     if ('gif' !== strtolower($format)) {
         throw new InvalidArgumentException('Animated picture is currently only supported on gif');
     }
     foreach (array('Loops' => $loops, 'Delay' => $delay) as $name => $value) {
         if (!is_int($value) || $value < 0) {
             throw new InvalidArgumentException(sprintf('%s must be a positive integer.', $name));
         }
     }
     try {
         foreach ($this as $offset => $layer) {
             $this->resource->setIteratorIndex($offset);
             $this->resource->setFormat($format);
             $this->resource->setImageDelay($delay / 10);
             $this->resource->setImageTicksPerSecond(100);
             $this->resource->setImageIterations($loops);
         }
     } catch (\ImagickException $e) {
         throw new RuntimeException('Failed to animate layers', $e->getCode(), $e);
     }
     return $this;
 }
開發者ID:BeerMan88,項目名稱:yii,代碼行數:26,代碼來源:Layers.php

示例4: add_watermark

 public function add_watermark($path, $x = 0, $y = 0)
 {
     $watermark = new Imagick($path);
     $draw = new ImagickDraw();
     $draw->composite($watermark->getImageCompose(), $x, $y, $watermark->getImageWidth(), $watermark->getimageheight(), $watermark);
     if ($this->type == 'gif') {
         $image = $this->image;
         $canvas = new Imagick();
         $images = $image->coalesceImages();
         foreach ($image as $frame) {
             $img = new Imagick();
             $img->readImageBlob($frame);
             $img->drawImage($draw);
             $canvas->addImage($img);
             $canvas->setImageDelay($img->getImageDelay());
         }
         $image->destroy();
         $this->image = $canvas;
     } else {
         $this->image->drawImage($draw);
     }
 }
開發者ID:wjyGamedev,項目名稱:xuezhiweb,代碼行數:22,代碼來源:ImageUtil.php

示例5: waterMarkFont

 function waterMarkFont()
 {
     if ($this->param['water_mark_color']) {
         $color = $this->param['water_mark_color'];
     } else {
         $color = '#000000';
     }
     $r = hexdec(substr($color, 1, 2));
     $g = hexdec(substr($color, 3, 2));
     $b = hexdec(substr($color, 5, 2));
     $draw = new ImagickDraw();
     $draw->setFillColor(new ImagickPixel($color));
     //設置填充顏色
     $draw->setFont($this->param['water_mark_font']);
     //設置文本字體,要求ttf或者ttc字體,可以絕對或者相對路徑
     $draw->setFontSize($this->param['water_mark_fontsize']);
     //設置字號
     switch ($this->param['water_mark_pos']) {
         case 0:
         case 1:
             $gravity = Imagick::GRAVITY_NORTHWEST;
             //'NorthWest';
             break;
         case 2:
             $gravity = Imagick::GRAVITY_NORTH;
             //'North';
             break;
         case 3:
             $gravity = Imagick::GRAVITY_NORTHEAST;
             //'NorthEast';
             break;
         case 4:
             $gravity = Imagick::GRAVITY_WEST;
             //'West';
             break;
         case 5:
             $gravity = Imagick::GRAVITY_CENTER;
             //'Center';
             break;
         case 6:
             $gravity = Imagick::GRAVITY_EAST;
             //'East';
             break;
         case 7:
             $gravity = Imagick::GRAVITY_SOUTHWEST;
             //'SouthWest';
             break;
         case 8:
             $gravity = Imagick::GRAVITY_SOUTH;
             //'South';
             break;
         case 9:
             $gravity = Imagick::GRAVITY_SOUTHEAST;
             break;
     }
     $draw->setGravity($gravity);
     if ($this->image_type == 'GIF') {
         $color_transparent = new ImagickPixel("transparent");
         $dest = new Imagick();
         foreach ($this->image as $frame) {
             $page = $frame->getImagePage();
             $tmp = new Imagick();
             $tmp->newImage($page['width'], $page['height'], $color_transparent, 'gif');
             $tmp->compositeImage($frame, Imagick::COMPOSITE_OVER, $page['x'], $page['y']);
             $tmp->annotateImage($draw, 0, 0, $this->param['water_mark_angle'], $this->param['water_mark_string']);
             $dest->addImage($tmp);
             $dest->setImagePage($tmp->getImageWidth(), $tmp->getImageHeight(), 0, 0);
             $dest->setImageDelay($frame->getImageDelay());
             $dest->setImageDispose($frame->getImageDispose());
         }
         $dest->coalesceImages();
         $this->image->destroy();
         $this->image = $dest;
     } else {
         if ($this->param['water_mark_opacity']) {
             $draw->setFillOpacity($this->param['water_mark_opacity'] / 100);
         }
         $this->image->annotateImage($draw, 0, 0, $this->param['water_mark_angle'], $this->param['water_mark_string']);
     }
 }
開發者ID:vluo,項目名稱:myPoto,代碼行數:80,代碼來源:image_imagick.php

示例6: animate

 /**
  * {@inheritdoc}
  */
 public function animate(array $frames, $delay = 20)
 {
     $gif = new \Imagick();
     $gif->setFormat('gif');
     foreach ($frames as $im) {
         if ($im instanceof Imanee) {
             $frame = $im->getResource()->getResource();
         } else {
             $frame = new \Imagick($im);
         }
         $frame->setImageDelay($delay);
         $gif->addImage($frame);
     }
     $imagickResource = new ImagickResource();
     $imagickResource->setResource($gif);
     $imanee = new Imanee();
     $imanee->setResource($imagickResource);
     $imanee->setFormat('gif');
     return $imanee;
 }
開發者ID:robth82,項目名稱:imanee,代碼行數:23,代碼來源:ImagickResource.php

示例7: foreach

 /**
  * Resamples an image to a new copy
  *
  * @param Imagick $dst_image
  * @param Imagick $src_image
  * @param int $dst_x
  * @param int $dst_y
  * @param int $src_x
  * @param int $src_y
  * @param int $dst_w
  * @param int $dst_h
  * @param int $src_w
  * @param int $src_h
  * @return bool
  */
 function zp_resampleImage($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
 {
     foreach ($src_image->getImageProfiles() as $name => $profile) {
         $dst_image->profileImage($name, $profile);
     }
     $result = true;
     $src_image = $src_image->coalesceImages();
     foreach ($src_image as $frame) {
         $frame->cropImage($src_w, $src_h, $src_x, $src_y);
         $frame->setImagePage(0, 0, 0, 0);
     }
     $src_image = $src_image->coalesceImages();
     foreach ($src_image as $frame) {
         $frame->resizeImage($dst_w, $dst_h, Imagick::FILTER_LANCZOS, 1);
         $dst_image->setImageDelay($frame->getImageDelay());
         $result &= $dst_image->compositeImage($frame, Imagick::COMPOSITE_OVER, $dst_x, $dst_y);
         if ($dst_image->getNumberImages() < $src_image->getNumberImages()) {
             $result &= $dst_image->addImage(zp_createImage($dst_image->getImageWidth(), $dst_image->getImageHeight()));
         }
         if (!$result) {
             break;
         }
     }
     return $result;
 }
開發者ID:ariep,項目名稱:ZenPhoto20-DEV,代碼行數:40,代碼來源:lib-Imagick.php

示例8: watchmark

 /**
  * 截取圖片
  *
  * @param int $x 開始坐標x
  * @param int $y 坐標y
  * @param int $width
  * @param int $height
  * @param string $savepath 文件存放路徑,未提供則修改當前
  */
 public function watchmark($x, $y, $savepath = NULL)
 {
     if (!$this->waterImage instanceof \Imagick) {
         throw new MediaException('Watermark source is invalid.');
     }
     if ($format == 'GIF') {
         $format = $this->getImageFormat();
         $transparent = new \ImagickPixel("rgba(0, 0, 0, 0)");
         // 透明色
         $tmpImage = new \Imagick();
         foreach ($this->image as $frame) {
             $page = $frame->getImagePage();
             $tmp = new \Imagick();
             $tmp->newImage($page['width'], $page['height'], $transparent, $format);
             $tmp->compositeImage($frame, \Imagick::COMPOSITE_DEFAULT, $page['x'], $page['y']);
             if (min($this->getOriginalSize()) > $this->waterStart) {
                 $tmp->compositeImage($this->waterImage, \Imagick::COMPOSITE_DEFAULT, $x, $y);
             }
             $tmpImage->addImage($tmp);
             $tmpImage->setImagePage($tmp->getImageWidth(), $tmp->getImageHeight(), 0, 0);
             $tmpImage->setImageDelay($frame->getImageDelay());
             $tmpImage->setImageDispose($frame->getImageDispose());
         }
     } else {
         $tmpImage = new \Imagick();
         $tmpImage->addimage($this->image);
         if (min($this->getOriginalSize()) > $this->waterStart) {
             $tmpImage->compositeImage($this->waterImage, \Imagick::COMPOSITE_DEFAULT, $x, $y);
         }
     }
     if ($savepath == NULL) {
         //縮放當前
         $this->image = $tmpImage;
     } else {
         //寫入儲存
         $this->writeToPath($savepath, $tmpImage);
     }
     return $this;
 }
開發者ID:ZhuJingfa,項目名稱:HuiLib,代碼行數:48,代碼來源:ImageBase.php

示例9: addFont

 public function addFont($text, $font, $startX = 0, $startY = 12, $color = 'black', $fontSize = 12, $alpha = 1, $degree = 0)
 {
     if (!$text) {
         return $this;
     }
     if (!is_readable($font)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '參數錯誤,font:' . $font, '字型檔案不存在!');
     }
     if (!($startX >= 0 && $startY >= 0)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '起始點錯誤,startX:' . $startX . ',startY:' . $startY, '水平、垂直的起始點一定要大於 0!');
     }
     if (!is_string($color)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '色碼錯誤!', '請確認色碼格式,目前隻支援 字串HEX 格式!');
     }
     if (!($fontSize > 0)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '參數錯誤,fontSize:' . $fontSize, '文字大小一定要大於 0!');
     }
     if (!($alpha && is_numeric($alpha) && $alpha >= 0 && $alpha <= 1)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '參數錯誤,alpha:' . $alpha, '參數 alpha 一定要是 0 或 1!');
     }
     if (!is_numeric($degree %= 360)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '角度一定要是數字,degree:' . $degree, '請確認 GD 函式庫中是否有支援 imagerotate 函式!');
     }
     if (!($draw = $this->_createFont($font, $fontSize, $color, $alpha))) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', ' Create 文字物件失敗', '請程式設計者確認狀況!');
     }
     if ($this->format == 'gif') {
         $newImage = new Imagick();
         $newImage->setFormat($this->format);
         $imagick = $this->image->clone()->coalesceImages();
         do {
             $temp = new Imagick();
             $temp->newImage($this->dimension['width'], $this->dimension['height'], new ImagickPixel('transparent'));
             $temp->compositeImage($imagick, imagick::COMPOSITE_DEFAULT, 0, 0);
             $temp->annotateImage($draw, $startX, $startY, $degree, $text);
             $newImage->addImage($temp);
             $newImage->setImageDelay($imagick->getImageDelay());
         } while ($imagick->nextImage());
     } else {
         $newImage = $this->image->clone();
         $newImage->annotateImage($draw, $startX, $startY, $degree, $text);
     }
     return $this->_updateImage($newImage);
 }
開發者ID:comdan66,項目名稱:zeusdesign,代碼行數:44,代碼來源:ImageImagickUtility.php

示例10: _imageickThumb

 private function _imageickThumb($url, $type, $new_w = 765, $new_h = 1000, $self = false, $trim = false)
 {
     $srcFile = $url;
     if ($self) {
         $destFile = $url;
     } else {
         $destFile = $type;
     }
     if ($new_w <= 0 || !file_exists($srcFile)) {
         return false;
     }
     $src = new Imagick($srcFile);
     $image_format = strtolower($src->getImageFormat());
     if ($image_format != 'jpeg' && $image_format != 'gif' && $image_forumat != 'bmp' && $image_format != 'png' && $image_format != 'jpg') {
         return false;
     }
     $src_page = $src->getImagePage();
     $src_w = $src_page['width'];
     $rate_w = $new_w / $src_w;
     if ($rate_w >= 1) {
         return false;
     }
     if ($new_h == -1) {
         $new_h = $rate_w * $src_page['height'];
     }
     //如果是 jpg jpeg gif
     if ($image_format != 'gif') {
         $dest = $src;
         if (!$trim) {
             $dest->thumbnailImage($new_w, $new_h, true);
         } else {
             $dest->cropthumbnailImage($new_w, $new_h);
         }
         $dest->writeImage($destFile);
         $dest->clear();
         //gif需要以幀一幀的處理
     } else {
         $dest = new Imagick();
         $color_transparent = new ImagickPixel("transparent");
         //透明色
         foreach ($src as $img) {
             $page = $img->getImagePage();
             if ($new_h == -1) {
                 $new_h = $new_w / $page['width'] * $src_page['hight'];
             }
             $tmp = new Imagick();
             $tmp->newImage($page['width'], $page['height'], $color_transparent, 'gif');
             $tmp->compositeImage($img, Imagick::COMPOSITE_OVER, $page['x'], $page['y']);
             if (!$trim) {
                 $tmp->thumbnailImage($new_w, $new_h, true);
             } else {
                 $tmp->cropthumbnailImage($new_w, $new_h);
             }
             $dest->addImage($tmp);
             $dest->setImagePage($tmp->getImageWidth(), $tmp->getImageHeight(), 0, 0);
             $dest->setImageDelay($img->getImageDelay());
             $dest->setImageDispose($img->getImageDispose());
         }
         $dest->coalesceImages();
         $dest->writeImages($destFile, true);
         $dest->clear();
     }
 }
開發者ID:armebayelm,項目名稱:thinksns-vietnam,代碼行數:63,代碼來源:ImageHooks.class.php

示例11: filesize

    //    var_dump($identifyInfo);
    $imagickFrame->writeImage($frame . "debug.gif");
    //if (false) {
    $paletteImage = clone $imagickFrame;
    $paletteImage->quantizeImage(256, Imagick::COLORSPACE_YIQ, 0, false, false);
    //$imagickFrame->setImageDepth(8);
    //$imagickFrame->quantizeImage(15,Imagick::COLORSPACE_TRANSPARENT,0,false,false);
    //Imagick::mapImage ( Imagick $map , bool $dither )
    $imagickFrame->remapImage($paletteImage, Imagick::DITHERMETHOD_FLOYDSTEINBERG);
    //}
    //Imagick::DITHERMETHOD_RIEMERSMA
    //Imagick::DITHERMETHOD_FLOYDSTEINBERG
    //6.9meg
    //$imagickFrame->quantizeImage(255, Imagick::COLORSPACE_RGB, 0, true, false );
    //orderedPosterizeImage ( string $threshold_map [, int $channel = Imagick::CHANNEL_ALL ] )
    //posterizeImage ( int $levels , bool $dither )
    //$imagickFrame->remapimage()
    $imagickFrame->setImageDelay($frameDelay);
    $animation->addImage($imagickFrame);
}
//Zero default - 8 biggest tree
//$animation->quantizeImages(255, Imagick::COLORSPACE_RGB, 0, false, false );
//$animation->quantizeImages(255, Imagick::COLORSPACE_RGB, 8, true, false );
//Imagick::clutImage ( Imagick $lookup_table [, float $channel = Imagick::CHANNEL_DEFAULT ] )
$animation->setFormat('gif');
$animation->setImageFormat('gif');
$outputGif = $animation->deconstructImages();
$outputFilename = $animDir . ".gif";
$outputGif->writeImages($outputFilename, true);
$filesize = filesize($outputFilename);
echo "output is {$outputFilename}, filesize is {$filesize} \n";
開發者ID:finelinePG,項目名稱:imagick,代碼行數:31,代碼來源:gifitplx.php

示例12: add_full_watermark

 public function add_full_watermark($path, $x = 0, $y = 0)
 {
     $watermark = new Imagick($path);
     $draw = new ImagickDraw();
     $image = $this->image;
     $image_w = $image->getImageWidth();
     $image_h = $image->getimageheight();
     $water_w = $watermark->getImageWidth();
     $water_h = $watermark->getimageheight();
     $a = floor($image_w / $water_w);
     $b = floor($image_h / $water_h);
     //$offset_x = ($image_w>$water_w)?floor($image_w%$water_w/2):0;
     //$offset_y = ($image_h>$water_h)?floor($image_h%$water_h/2):0;
     $offset_x = $offset_y = 0;
     for ($i = 0; $i <= $a; $i++) {
         for ($j = 0; $j <= $b; $j++) {
             $draw->composite($watermark->getImageCompose(), $i * $water_w + $offset_x, $j * $water_h + $offset_y, $water_w, $water_h, $watermark);
         }
     }
     if ($this->type == 'gif') {
         $image = $this->image;
         $canvas = new Imagick();
         $images = $image->coalesceImages();
         foreach ($image as $frame) {
             $img = new Imagick();
             $img->readImageBlob($frame);
             $img->drawImage($draw);
             $canvas->addImage($img);
             $canvas->setImageDelay($img->getImageDelay());
         }
         $image->destroy();
         $this->image = $canvas;
     } else {
         $this->image->drawImage($draw);
     }
 }
開發者ID:jasonjiang123,項目名稱:shuijian,代碼行數:36,代碼來源:JImage.class.php

示例13: copySize

 private function copySize($size)
 {
     list($width, $height) = getimagesize($this->publicPath());
     list($newWidth, $newHeight, $destinationX, $destinationY, $sourceX, $sourceY, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight) = $this->calcSizes($size, $width, $height);
     $thumb = imagecreatetruecolor($newWidth, $newHeight);
     imagealphablending($thumb, false);
     imagesavealpha($thumb, true);
     $transparent = imagecolorallocatealpha($thumb, 255, 255, 255, 127);
     imagefilledrectangle($thumb, 0, 0, $newWidth, $newHeight, $transparent);
     if (strtolower($this->extension) == 'jpg') {
         $source = imagecreatefromjpeg($this->publicPath());
         imagecopyresampled($thumb, $source, $destinationX, $destinationY, $sourceX, $sourceY, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight);
         imagejpeg($thumb, $this->publicPath($size));
     } elseif (strtolower($this->extension) == 'jpeg') {
         $source = imagecreatefromjpeg($this->publicPath());
         imagecopyresampled($thumb, $source, $destinationX, $destinationY, $sourceX, $sourceY, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight);
         imagejpeg($thumb, $this->publicPath($size));
     } elseif (strtolower($this->extension) == 'png') {
         $source = imagecreatefrompng($this->publicPath());
         imagecopyresampled($thumb, $source, $destinationX, $destinationY, $sourceX, $sourceY, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight);
         imagepng($thumb, $this->publicPath($size));
     } elseif (strtolower($this->extension) == 'gif') {
         if (extension_loaded('imagick')) {
             $image = new \Imagick($this->publicPath());
             $image = $image->coalesceimages();
             $final = new \Imagick();
             foreach ($image as $frame) {
                 $canvas = new \Imagick();
                 $frame->cropimage($sourceWidth, $sourceHeight, $sourceX, $sourceY);
                 $frame->thumbnailImage($destinationWidth, $destinationHeight);
                 $canvas->newImage($newWidth, $newHeight, new \ImagickPixel('none'));
                 $delay = $frame->getImageDelay();
                 $canvas->setImageDelay($delay);
                 $canvas->compositeImage($frame, \Imagick::COMPOSITE_OVER, $destinationX, $destinationY);
                 $final->addimage($canvas);
             }
             $final->writeImages($this->publicPath($size), true);
         } else {
             $source = imagecreatefromgif($this->publicPath());
             imagecopyresampled($thumb, $source, $destinationX, $destinationY, $sourceX, $sourceY, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight);
             imagegif($thumb, $this->publicPath($size));
         }
     }
 }
開發者ID:hlacos,項目名稱:attachment5,代碼行數:44,代碼來源:Attachment.php

示例14: imgSquareFit

 /**
  * Put image to square
  *
  * @param  string $path image file
  * @param  int $width square width
  * @param  int $height square height
  * @param int|string $align reserved
  * @param int|string $valign reserved
  * @param  string $bgcolor square background color in #rrggbb format
  * @param  string $destformat image destination format
  * @param  int $jpgQuality JEPG quality (1-100)
  * @return false|string
  * @author Dmitry (dio) Levashov
  * @author Alexey Sukhotin
  */
 protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null, $jpgQuality = null)
 {
     if (($s = getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     /* Coordinates for image over square aligning */
     $y = ceil(abs($height - $s[1]) / 2);
     $x = ceil(abs($width - $s[0]) / 2);
     if (!$jpgQuality) {
         $jpgQuality = $this->options['jpgQuality'];
     }
     elFinder::extendTimeLimit(300);
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             if ($bgcolor === 'transparent') {
                 $bgcolor = 'rgba(255, 255, 255, 0.0)';
             }
             $ani = $img->getNumberImages() > 1;
             if ($ani && is_null($destformat)) {
                 $img1 = new Imagick();
                 $img1->setFormat('gif');
                 $img = $img->coalesceImages();
                 do {
                     $gif = new Imagick();
                     $gif->newImage($width, $height, new ImagickPixel($bgcolor));
                     $gif->setImageColorspace($img->getImageColorspace());
                     $gif->setImageFormat('gif');
                     $gif->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
                     $gif->setImageDelay($img->getImageDelay());
                     $gif->setImageIterations($img->getImageIterations());
                     $img1->addImage($gif);
                     $gif->clear();
                 } while ($img->nextImage());
                 $img1 = $img1->optimizeImageLayers();
                 $result = $img1->writeImages($path, true);
             } else {
                 if ($ani) {
                     $img->setFirstIterator();
                 }
                 $img1 = new Imagick();
                 $img1->newImage($width, $height, new ImagickPixel($bgcolor));
                 $img1->setImageColorspace($img->getImageColorspace());
                 $img1->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
                 $result = $this->imagickImage($img1, $path, $destformat, $jpgQuality);
             }
             $img1->clear();
             $img->clear();
             return $result ? $path : false;
             break;
         case 'convert':
             extract($this->imageMagickConvertPrepare($path, $destformat, $jpgQuality, $s));
             if ($bgcolor === 'transparent') {
                 $bgcolor = 'rgba(255, 255, 255, 0.0)';
             }
             $cmd = sprintf('convert -size %dx%d "xc:%s" png:- | convert%s%s png:-  %s -geometry +%d+%d -compose over -composite%s %s', $width, $height, $bgcolor, $coalesce, $jpgQuality, $quotedPath, $x, $y, $deconstruct, $quotedDstPath);
             $result = false;
             if ($this->procExec($cmd) === 0) {
                 $result = true;
             }
             return $result ? $path : false;
             break;
         case 'gd':
             $img = $this->gdImageCreate($path, $s['mime']);
             if ($img && false != ($tmp = imagecreatetruecolor($width, $height))) {
                 $this->gdImageBackground($tmp, $bgcolor);
                 if ($bgcolor === 'transparent' && ($destformat === 'png' || $s[2] === IMAGETYPE_PNG)) {
                     $bgNum = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
                     imagefill($tmp, 0, 0, $bgNum);
                 }
                 if (!imagecopy($tmp, $img, $x, $y, 0, 0, $s[0], $s[1])) {
                     return false;
                 }
                 $result = $this->gdImage($tmp, $path, $destformat, $s['mime'], $jpgQuality);
                 imagedestroy($img);
                 imagedestroy($tmp);
                 return $result ? $path : false;
             }
             break;
     }
//.........這裏部分代碼省略.........
開發者ID:bigbrush,項目名稱:yii2-big,代碼行數:101,代碼來源:elFinderVolumeDriver.class.php

示例15: createImage

 /**
  * 創建圖片
  * @param array $options 參數數組
  * 必須填寫的參數:
  *   save_type: int 保存類型 1:保存圖片路徑自定義 2:保存後的圖片覆蓋原圖片
  * 選填的參數:
  *   save_path: string 圖片保存地址,包括目錄和文件名
  *   resize_width: int 保存後圖片的寬,默認取原圖寬
  *   resize_height: int 保存後圖片的高,默認取原圖高
  *   quality: int 圖片壓縮質量,1-100,數字越大質量越好,默認取85
  * @return array
  */
 public function createImage($options)
 {
     $resArr = ['code' => 0];
     $acceptType = ['image/png', 'image/jpeg', 'image/gif'];
     if ($this->image == null) {
         $resArr['code'] = 1;
         $resArr['message'] = '打開圖片失敗';
     } else {
         if (!in_array($this->mimeType, $acceptType)) {
             $resArr['code'] = 2;
             $resArr['message'] = '圖片類型不支持';
         } else {
             if ($options['save_type'] == 1) {
                 $savePath = str_replace('\\', '/', $options['save_path']);
             } else {
                 if ($options['save_type'] == 2) {
                     $savePath = $this->originalName;
                 } else {
                     $resArr['code'] = 3;
                     $resArr['message'] = '保存類型不正確';
                     return $resArr;
                 }
             }
             $resize_width = isset($options['resize_width']) && (int) $options['resize_width'] > 0 ? (int) $options['resize_width'] : $this->originalWidth;
             $resize_height = isset($options['resize_height']) && (int) $options['resize_height'] > 0 ? (int) $options['resize_height'] : $this->originalHeight;
             $quality = isset($options['quality']) && (int) $options['quality'] > 0 && (int) $options['quality'] <= 100 ? (int) $options['quality'] : 85;
             $now_quality = $this->image->getImageCompressionQuality();
             if ($now_quality == 0) {
                 $need_quality = $quality;
             } else {
                 $need_quality = ceil($now_quality * $quality / 100);
             }
             if ($this->mimeType == 'image/gif') {
                 //處理gif動態圖片
                 $image = $this->image;
                 $images = $image->coalesceImages();
                 $canvas = new \Imagick();
                 foreach ($images as $eImage) {
                     $img = new \Imagick();
                     $img->readImageBlob($eImage);
                     $img->resizeImage($resize_width, $resize_height, \Imagick::FILTER_CATROM, 1, true);
                     $img->setImageCompressionQuality($need_quality);
                     $canvas->addImage($img);
                     $canvas->setImageDelay($img->getImageDelay());
                     $img->destroy();
                 }
                 $this->image = $canvas;
                 $image->destroy();
                 $canvas->destroy();
             } else {
                 if ($this->mimeType == 'image/jpeg') {
                     $this->image->resizeImage($resize_width, $resize_height, \Imagick::FILTER_CATROM, 1, true);
                     $this->image->setImageCompression(\Imagick::COMPRESSION_JPEG);
                     $this->image->setImageCompressionQuality($need_quality);
                 } else {
                     $this->image->resizeImage($resize_width, $resize_height, \Imagick::FILTER_CATROM, 1, true);
                     $this->image->setImageCompressionQuality($need_quality);
                 }
             }
             $writeRes = $this->image->writeImage($savePath);
             if ($writeRes) {
                 //修改寫入成功後文件的操作權限
                 chmod($savePath, 0777);
                 $resArr['data'] = ['image_name' => $savePath, 'image_width' => $this->image->getImageWidth(), 'image_height' => $this->image->getImageHeight()];
             } else {
                 $resArr['code'] = 4;
                 $resArr['message'] = '寫入文件失敗';
             }
         }
     }
     return $resArr;
 }
開發者ID:a07061625,項目名稱:image,代碼行數:84,代碼來源:ImageMagickApi.php


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