本文整理匯總了PHP中Imagick::evaluateImage方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::evaluateImage方法的具體用法?PHP Imagick::evaluateImage怎麽用?PHP Imagick::evaluateImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::evaluateImage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _watermark
protected function _watermark($filename, $position, $padding = 5)
{
extract(parent::_watermark($filename, $position, $padding));
$wmimage = new \Imagick();
$wmimage->readImage($filename);
$wmimage->evaluateImage(\Imagick::EVALUATE_MULTIPLY, $this->config['watermark_alpha'] / 100, \Imagick::CHANNEL_ALPHA);
$this->imagick->compositeImage($wmimage, \Imagick::COMPOSITE_DEFAULT, $x, $y);
}
示例2: fopen
}
$ctx = stream_context_create($opts);
// DEBUG
$debug = fopen('/tmp/maplog', 'a');
fwrite($debug, $v->{'url'} . ($v->{'grid'} ? '' : "&width={$w}&height={$h}&bbox={$bbox}") . "\n");
fclose($debug);
$handle = fopen($tmp_dir . $id . '.png', 'w');
fwrite($handle, file_get_contents($v->{'url'} . ($v->{'grid'} ? '' : "&width={$w}&height={$h}&bbox={$bbox}"), false, $ctx));
fclose($handle);
if (!getimagesize($tmp_dir . $id . '.png')) {
$img = new Imagick('img/blank.png');
} else {
$img = new Imagick($tmp_dir . $id . '.png');
}
// leave initially opaque cells alone
$img->evaluateImage(Imagick::EVALUATE_MULTIPLY, $v->{'opacity'}, Imagick::CHANNEL_ALPHA);
$canvas->compositeImage($img, imagick::COMPOSITE_OVER, $v->{'x'}, $v->{'y'});
}
}
foreach ($json->{'legends'} as $k => $v) {
$handle = fopen($tmp_dir . $id . '.' . count($legends) . '.png', 'w');
fwrite($handle, @file_get_contents(mkLegendUrl($v)));
fclose($handle);
// use a blank image if no real legend came through
if (!getimagesize($tmp_dir . $id . '.' . count($legends) . '.png')) {
array_push($legends, new Imagick('img/blank.png'));
} else {
array_push($legends, new Imagick($tmp_dir . $id . '.' . count($legends) . '.png'));
}
if ($legends[count($legends) - 1]->getImageWidth() > $legSize[0]) {
$legSize[0] = $legends[count($legends) - 1]->getImageWidth();
示例3: watermark
/**
* @param $watermarkImage
* @param int $positionX
* @param int $positionY
* @param int $watermarkImageOpacity
* @param bool $repeat
*/
public function watermark($watermarkImage, $positionX = 0, $positionY = 0, $watermarkImageOpacity = 30, $repeat = false)
{
Varien_Profiler::start(__METHOD__);
/** @var $watermark Imagick */
$watermark = new Imagick($watermarkImage);
//better method to blow up small images.
$watermark->setimageinterpolatemethod(Imagick::INTERPOLATE_NEARESTNEIGHBOR);
if ($this->_watermarkImageOpacity == null) {
$opc = $watermarkImageOpacity;
} else {
$opc = $this->getWatermarkImageOpacity();
}
$watermark->evaluateImage(Imagick::EVALUATE_MULTIPLY, $opc, Imagick::CHANNEL_ALPHA);
// how big are the images?
$iWidth = $this->getImageMagick()->getImageWidth();
$iHeight = $this->getImageMagick()->getImageHeight();
//resize watermark to configuration size
if ($this->getWatermarkWidth() && $this->getWatermarkHeigth() && $this->getWatermarkPosition() != self::POSITION_STRETCH) {
$watermark->scaleImage($this->getWatermarkWidth(), $this->getWatermarkHeigth());
}
// get watermark size
$wWidth = $watermark->getImageWidth();
$wHeight = $watermark->getImageHeight();
//check if watermark is still bigger then image.
if ($iHeight < $wHeight || $iWidth < $wWidth) {
// resize the watermark
$watermark->scaleImage($iWidth, $iHeight);
// get new size
$wWidth = $watermark->getImageWidth();
$wHeight = $watermark->getImageHeight();
}
$x = 0;
$y = 0;
switch ($this->getWatermarkPosition()) {
case self::POSITION_CENTER:
$x = ($iWidth - $wWidth) / 2;
$y = ($iHeight - $wHeight) / 2;
break;
case self::POSITION_STRETCH:
$watermark->scaleimage($iWidth, $iHeight);
break;
case self::POSITION_TOP_RIGHT:
$x = $iWidth - $wWidth;
break;
case self::POSITION_BOTTOM_LEFT:
$y = $iHeight - $wHeight;
break;
case self::POSITION_BOTTOM_RIGHT:
$x = $iWidth - $wWidth;
$y = $iHeight - $wHeight;
break;
default:
break;
}
$this->getImageMagick()->compositeImage($watermark, Imagick::COMPOSITE_OVER, $x, $y);
$watermark->clear();
$watermark->destroy();
Varien_Profiler::stop(__METHOD__);
}
示例4: post
include_once 'config.php';
include_once 'functions.php';
if (isPost()) {
// Get post parameters
$originX = post('originX');
$originY = post('originY');
$transparency = post('transparency');
$watermarkResize = post('markMin');
$originalImagePath = post('originalImage');
$watermarkImagePath = post('watermarkImage');
// Open images
$original = new Imagick($originalImagePath);
$watermark = new Imagick($watermarkImagePath);
// Set opacity for images with alpha channel and without
if ($watermark->getImageAlphaChannel()) {
$watermark->evaluateImage(Imagick::EVALUATE_DIVIDE, 1.0 / $transparency, Imagick::CHANNEL_ALPHA);
} else {
$watermark->setImageOpacity($transparency);
}
// Resize image
if ($watermarkResize > 1) {
$watermark->resizeImage($watermark->getImageWidth() / $watermarkResize, $watermark->getImageHeight() / $watermarkResize, Imagick::FILTER_LANCZOS, 1);
}
// Watermark block
$isPattern = post('isPattern');
if (bool($isPattern)) {
// Get watermark`s offset from original image
$initialX = (int) str_replace('px', '', post('x'));
$initialY = (int) str_replace('px', '', post('y'));
// Get watermark sizes
$watermarkWidth = $watermark->getImageWidth();
示例5: _background
/**
* Fill the image background.
* @param integer $r
* @param integer $g
* @param integer $b
* @param integer $opacity
*/
protected function _background($r, $g, $b, $opacity)
{
$background = new \Imagick();
$background->newImage($this->width, $this->height, new \ImagickPixel(sprintf('rgb(%d, %d, %d)', $r, $g, $b)));
if (!$background->getImageAlphaChannel()) {
$background->setImageAlphaChannel(\Imagick::ALPHACHANNEL_SET);
}
$background->setImageBackgroundColor(new \ImagickPixel('transparent'));
$background->evaluateImage(\Imagick::EVALUATE_MULTIPLY, $opacity / 100, \Imagick::CHANNEL_ALPHA);
$background->setColorspace($this->im->getColorspace());
if ($background->compositeImage($this->im, \Imagick::COMPOSITE_DISSOLVE, 0, 0)) {
$this->im = $background;
}
}
示例6: addOverlay
/**
* @param string $image
* @param int $x
* @param int $y
* @param int $alpha
* @return Pimcore_Image_Adapter_Imagick
*/
public function addOverlay($image, $x = 0, $y = 0, $alpha = null, $composite = "COMPOSITE_DEFAULT")
{
$image = ltrim($image, "/");
$image = PIMCORE_DOCUMENT_ROOT . "/" . $image;
// 100 alpha is default
if (empty($alpha)) {
$alpha = 100;
}
$alpha = round($alpha / 100, 1);
if (is_file($image)) {
$newImage = new Imagick();
$newImage->readimage($image);
$newImage->evaluateImage(Imagick::EVALUATE_MULTIPLY, $alpha, Imagick::CHANNEL_ALPHA);
$this->resource->compositeImage($newImage, constant("Imagick::" . $composite), $x, $y);
}
$this->reinitializeImage();
return $this;
}
示例7: _watermark
/**
* @param array $options
* 'watermark' => waImage|string $watermark
* 'opacity' => float|int 0..1
* 'align' => self::ALIGN_* const
* 'font_file' => null|string If null - will be used some default font. Note: use when watermark option is text
* 'font_size' => float Size of font. Note: use when watermark option is text
* 'font_color' => string Hex-formatted of color (without #). Note: use when watermark option is text
* 'text_orientation' => self::ORIENTATION_* const. Note: use when watermark option is text
* @return mixed
*/
protected function _watermark($options)
{
// export options to php-vars
foreach ($options as $name => $value) {
${$name} = $value;
}
$opacity = min(max($opacity, 0), 1);
/**
* @var waImage $watermark
*/
if ($watermark instanceof waImage) {
$offset = $this->calcWatermarkOffset($watermark->width, $watermark->height, $align);
$watermark = new Imagick($watermark->file);
$watermark->evaluateImage(Imagick::EVALUATE_MULTIPLY, $opacity, Imagick::CHANNEL_ALPHA);
$this->im->compositeImage($watermark, Imagick::COMPOSITE_DEFAULT, $offset[0], $offset[1]);
$watermark->clear();
$watermark->destroy();
} else {
$text = (string) $watermark;
if (!$text) {
return;
}
$font_size = 24 * $font_size / 18;
// 24px = 18pt
$font_color = new ImagickPixel('#' . $font_color);
$watermark = new ImagickDraw();
$watermark->setFillColor($font_color);
$watermark->setFillOpacity($opacity);
if ($font_file && file_exists($font_file)) {
$watermark->setFont($font_file);
}
$watermark->setFontSize($font_size);
// Throws ImagickException on error
$metrics = $this->im->queryFontMetrics($watermark, $text);
$width = $metrics['textWidth'];
$height = $metrics['textHeight'];
if ($text_orientation == self::ORIENTATION_VERTICAL) {
list($width, $height) = array($height, $width);
}
$offset = $this->calcWatermarkTextOffset($width, $height, $align, $text_orientation);
$this->im->annotateImage($watermark, $offset[0], $offset[1], $text_orientation == self::ORIENTATION_VERTICAL ? -90 : 0, $text);
$watermark->clear();
$watermark->destroy();
}
}
示例8: writeWatermarkIm
public function writeWatermarkIm($opacity = 50, $marginH = 0, $marginV = 0, $positionWatermarkLeftRight = 'c', $positionWatermarkTopBottom = 'c')
{
//add Watermark
list($imageCreateFunc, $imageSaveFunc) = $this->_watermark->_getFunctionNames();
$watermarkImage = $imageCreateFunc($this->_watermark->_getImage());
//get base image
list($imageCreateFunc, $imageSaveFunc) = $this->_getFunctionNames();
$baseImage = @$imageCreateFunc($this->_image);
if (!$baseImage) {
return false;
}
//Calculate margins
if ($positionWatermarkLeftRight == 'r') {
$marginH = imagesx($baseImage) - imagesx($watermarkImage) - $marginH;
}
if ($positionWatermarkLeftRight == 'c') {
$marginH = imagesx($baseImage) / 2 - imagesx($watermarkImage) / 2 - $marginH;
}
if ($positionWatermarkTopBottom == 'b') {
$marginV = imagesy($baseImage) - imagesy($watermarkImage) - $marginV;
}
if ($positionWatermarkTopBottom == 'c') {
$marginV = imagesy($baseImage) / 2 - imagesy($watermarkImage) / 2 - $marginV;
}
$image = new Imagick($this->_image);
$image->coalesceimages();
$watermark = new Imagick();
$watermark->readimage($this->_watermark->_getImage());
$watermark->evaluateImage(Imagick::EVALUATE_DIVIDE, 100 / $opacity, Imagick::CHANNEL_ALPHA);
if ($imageSaveFunc == 'ImageGIF') {
if (XenForo_Application::getOptions()->xengalleryWatermarkAnimated) {
try {
foreach ($image as $frame) {
$frame->compositeImage($watermark, imagick::COMPOSITE_OVER, $marginH, $marginV);
}
if (!$image->writeimages($this->tmpFile, true)) {
throw new Exception('Cannot save file ' . $this->tmpFile);
}
} catch (Exception $e) {
return false;
}
} else {
return false;
}
} else {
$image->compositeImage($watermark, imagick::COMPOSITE_OVER, $marginH, $marginV);
if (!$image->writeimage($this->tmpFile)) {
throw new Exception('Cannot save file ' . $this->tmpFile);
}
}
//Set new main image
$this->_setNewMainImage($this->tmpFile);
$image->destroy();
$watermark->destroy();
return true;
}
示例9: image_constrain_imagick
/**
* Создание превью средствами imagick
* @param $src_file исходный файл
* @param $dst_file файл с результатом
* @param max_w максимальная ширина
* @param max_h максимальная высота
* @return bool
*/
private function image_constrain_imagick($src_file, $dst_file, $max_w, $max_h, $watermark = null, $watermark_offet_x = 0, $watermark_offet_y = 0, $watermark_opacity = 1, $sharpen = 0.2)
{
$thumb = new Imagick();
// Читаем изображение
if (!$thumb->readImage($src_file)) {
return false;
}
// Размеры исходного изображения
$src_w = $thumb->getImageWidth();
$src_h = $thumb->getImageHeight();
// Нужно ли обрезать?
if (!$watermark && $src_w <= $max_w && $src_h <= $max_h) {
// Нет - просто скопируем файл
if (!copy($src_file, $dst_file)) {
return false;
}
return true;
}
// Размеры превью при пропорциональном уменьшении
list($dst_w, $dst_h) = $this->calc_contrain_size($src_w, $src_h, $max_w, $max_h);
// Уменьшаем
$thumb->thumbnailImage($dst_w, $dst_h);
// Устанавливаем водяной знак
if ($watermark && is_readable($watermark)) {
$overlay = new Imagick($watermark);
//$overlay->setImageOpacity($watermark_opacity);
//$overlay_compose = $overlay->getImageCompose();
$overlay->evaluateImage(Imagick::EVALUATE_MULTIPLY, $watermark_opacity, Imagick::CHANNEL_ALPHA);
// Get the size of overlay
$owidth = $overlay->getImageWidth();
$oheight = $overlay->getImageHeight();
$watermark_x = min(($dst_w - $owidth) * $watermark_offet_x / 100, $dst_w);
$watermark_y = min(($dst_h - $oheight) * $watermark_offet_y / 100, $dst_h);
}
// Анимированные gif требуют прохода по фреймам
foreach ($thumb as $frame) {
// Уменьшаем
$frame->thumbnailImage($dst_w, $dst_h);
/* Set the virtual canvas to correct size */
$frame->setImagePage($dst_w, $dst_h, 0, 0);
// Наводим резкость
if ($sharpen > 0) {
$thumb->adaptiveSharpenImage($sharpen, $sharpen);
}
if (isset($overlay) && is_object($overlay)) {
// $frame->compositeImage($overlay, $overlay_compose, $watermark_x, $watermark_y, imagick::COLOR_ALPHA);
$frame->compositeImage($overlay, imagick::COMPOSITE_OVER, $watermark_x, $watermark_y, imagick::COLOR_ALPHA);
}
}
// Убираем комменты и т.п. из картинки
$thumb->stripImage();
// $thumb->setImageCompressionQuality(100);
// Записываем картинку
if (!$thumb->writeImages($dst_file, true)) {
return false;
}
// Уборка
$thumb->destroy();
if (isset($overlay) && is_object($overlay)) {
$overlay->destroy();
}
return true;
}
示例10: 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();
}
}
示例11: watermark
public function watermark($options)
{
// Make sure the resource handle is valid.
if (!$this->isLoaded()) {
throw new LogicException('No valid image was loaded.');
}
if ($options->opacity > 1) {
$options->opacity = $options->opacity / 100;
}
if ($options->type == 'text') {
if (isset($options->text)) {
$this->watermarkText($options);
}
} else {
if (isset($options->image)) {
$watermark = new Imagick($options->image);
$width = $this->getWidth();
$height = $this->getHeight();
$mw = $watermark->getImageWidth();
$mh = $watermark->getImageHeight();
switch ($options->position) {
default:
case 'center':
$x = floor(($width - $mw) / 2);
$y = floor(($height - $mh) / 2);
break;
case 'top-left':
$x = $options->margin;
$y = floor($mh / 2) + $options->margin;
break;
case 'top-right':
$x = $width - $mw - $options->margin;
$y = floor($mh / 2) + $options->margin;
break;
case 'center-left':
$x = 0 + $options->margin;
$y = floor(($height - $mh) / 2);
break;
case 'center-right':
$x = $width - $mw - $options->margin;
$y = floor(($height - $mh) / 2);
break;
case 'top-center':
$x = floor(($width - $mw) / 2);
$y = floor($mh / 2) + $options->margin;
break;
case 'bottom-center':
$x = floor(($width - $mw) / 2);
$y = $height - $mh - $options->margin;
break;
case 'bottom-left':
$x = 0 + $options->margin;
$y = $height - $mh - $options->margin;
break;
case 'bottom-right':
$x = $width - $mw - $options->margin;
$y = $height - $mh - $options->margin;
break;
}
if ($watermark->getImageFormat() == 'PNG') {
$watermark->evaluateImage(Imagick::EVALUATE_MULTIPLY, (double) $options->opacity, Imagick::CHANNEL_ALPHA);
} else {
$watermark->setImageOpacity((double) $options->opacity);
}
$this->handle->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y);
}
}
return $this;
}
示例12: setWatermark
/**
* Add watermark (text or image)
* @param string $image
* @param string $text
* @param string $watermarkImage
* @param string $type
* @param int $padding
* @param float|int $opacity
* @return string
*/
public static function setWatermark($image, $text = null, $watermarkImage = null, $type = 'png', $padding = 0, $opacity = 0.5)
{
if (is_null($text) && is_null($watermarkImage) || $text != '' && $watermarkImage != '') {
return $image;
}
$originalImage = self::data2image($image);
if (!is_null($watermarkImage) && $watermarkImage != '') {
$watermarkImage = self::data2image($watermarkImage);
}
if (!is_null($text) && $text !== '') {
// text watermark
$watermarkImage = new \Imagick();
$draw = new \ImagickDraw();
$draw->setFont(DIR_FW . 'lib/libs/capcha/DejaVuSans.ttf');
$draw->setFontSize(10);
$draw->setGravity(\imagick::GRAVITY_CENTER);
$textDArray = $watermarkImage->queryfontmetrics($draw, $text);
$watermarkImage->newImage($textDArray['textWidth'] + 7, $textDArray['textHeight'] + 1, new \ImagickPixel('none'));
$watermarkImage->setImageFormat('png');
}
// create watermark
$image_width = $originalImage->getImageWidth();
$image_height = $originalImage->getImageHeight();
$watermark_width = $watermarkImage->getImageWidth();
$watermark_height = $watermarkImage->getImageHeight();
// verify if watermark fits image
if ($image_width < $watermark_width + $padding || $image_height < $watermark_height + $padding) {
return self::image2data($originalImage, $type);
}
// define watermark position
$positions = [];
$positions[] = [0 + $padding, 0 + $padding];
$positions[] = [$image_width - $watermark_width - $padding, 0 + $padding];
$positions[] = [$image_width - $watermark_width - $padding, $image_height - $watermark_height - $padding];
$positions[] = [0 + $padding, $image_height - $watermark_height - $padding];
$min = null;
$min_colors = 0;
$textColor = 'black';
foreach ($positions as $position) {
$colors = $originalImage->getImageRegion($watermark_width, $watermark_height, $position[0], $position[1])->getImageColors();
if ($min === null || $colors <= $min_colors) {
$min = $position;
$min_colors = $colors;
}
}
$region = $originalImage->getImageRegion($watermark_width, $watermark_height, $min[0], $min[1]);
$region->scaleImage(1, 1);
$aColor = $region->getImagePixelColor(1, 1)->getColor();
$colorSum = $aColor['r'] + $aColor['g'] + $aColor['b'];
if ($colorSum < 390) {
$textColor = 'white';
}
if (!is_null($text) && $text !== '') {
$draw->setFillColor(new \ImagickPixel($textColor));
$draw->setFillOpacity($opacity);
$watermarkImage->annotateimage($draw, 0, 0, 0, $text);
} else {
$watermarkImage->evaluateImage(\Imagick::EVALUATE_MULTIPLY, $opacity, \Imagick::CHANNEL_ALPHA);
//$watermarkImage->setImageOpacity( $opacity );
}
// Put watermark
$originalImage->compositeImage($watermarkImage, \Imagick::COMPOSITE_OVER, $min[0], $min[1]);
return self::image2data($originalImage, $type);
}
示例13: _background
protected function _background($r, $g, $b, $opacity)
{
$color = sprintf("rgb(%d, %d, %d)", $r, $g, $b);
$pixel1 = new \ImagickPixel($color);
$opacity = $opacity / 100;
$pixel2 = new \ImagickPixel("transparent");
$background = new \Imagick();
$this->_image->setIteratorIndex(0);
while (true) {
$background->newImage($this->_width, $this->_height, $pixel1);
if (!$background->getImageAlphaChannel()) {
$background->setImageAlphaChannel(constant("Imagick::ALPHACHANNEL_SET"));
}
$background->setImageBackgroundColor($pixel2);
$background->evaluateImage(constant("Imagick::EVALUATE_MULTIPLY"), $opacity, constant("Imagick::CHANNEL_ALPHA"));
$background->setColorspace($this->_image->getColorspace());
$background->compositeImage($this->_image, constant("Imagick::COMPOSITE_DISSOLVE"), 0, 0);
if (!$this->_image->nextImage()) {
break;
}
}
$this->_image->clear();
$this->_image->destroy();
$this->_image = $background;
}
示例14: composite
/**
* 圖片合成,可以進行多張圖片的合成,也可以做圖片水印用
* <pre>
* 注意composite方法在和其它圖片處理方法一起使用時,composite必須第一個被調用
* 在圖片合成時,初始化對象傳遞imageData數據需要是一個二維數組。
* </pre>
* 數組中的每個成員也是數組,需要包含5個元素:
* - 表示圖像數據的blob字符串 (blob string)
* - 表示在畫布上放置圖像時相對錨點位置的 x 偏移的像素數(可能為負)
* - 表示在畫布上放置圖像時相對錨點位置的 y 偏移的像素數(可能為負)
* - 表示圖像不透明度(opacity)的浮點數,在 0.0 至 1.0 之間(包括 0.0 和 1.0)0表示全透明,1表示最不透明。
* - 畫布上錨點的位置,是以下之一:
* <pre>
* SAE_TOP_LEFT SAE_TOP_CENTER SAE_TOP_RIGHT SAE_CENTER_LEFT SAE_CENTER_CENTER
* SAE_CENTER_RIGHT SAE_BOTTOM_LEFT SAE_BOTTOM_CENTER SAE_BOTTOM_RIGHT
* </pre>
* 注意上麵的x偏移和y偏移,和錨點位置有關,如果選擇了錨點TOP_RIGHT,<br>
* 則x和y的偏移是指該圖片的TOP_RIGHT(右上角)相對於畫布的右上角的偏移;<br>
* 但如果選擇BOTTOM_LEFT(左下角)為錨點,則x/y偏移就是指該圖片的左下角<br>
* 相對於畫布的左下角的偏移量。<br>
* <b>偏移的正負同數學中的象限規定。</b><br>
* 圖片的放置順序同數組中出現的順序
*
* <code>
* <?php
* //從網絡上抓取要合成的多張圖片
* $img1 = file_get_contents('http://ss2.sinaimg.cn/bmiddle/53b05ae9t73817f6bf751&690');
* $img2 = file_get_contents('http://timg.sjs.sinajs.cn/miniblog2style/images/common/logo.png');
* $img3 = file_get_contents('http://i1.sinaimg.cn/home/deco/2009/0330/logo_home.gif');
*
* //實例化SaeImage並取得最大一張圖片的大小,稍後用於設定合成後圖片的畫布大小
* $img = new SaeImage( $img1 );
* $size = $img->getImageAttr();
*
* //清空$img數據
* $img->clean();
*
* //設定要用於合成的三張圖片(如果重疊,排在後麵的圖片會蓋住排在前麵的圖片)
* $img->setData( array(
* array( $img1, 0, 0, 1, SAE_TOP_LEFT ),
* array( $img2, 0, 0, 0.5, SAE_BOTTOM_RIGHT ),
* array( $img3, 0, 0, 1, SAE_BOTTOM_LEFT ),
* ) );
*
* //執行合成
* $img->composite($size[0], $size[1]);
*
* //輸出圖片
* $img->exec('jpg', true);
* ?>
* </code>
* @param int $width 設置畫布寬度
* @param int $height 設置畫布高度
* @param string $color 設置畫布顏色
* @return bool
* @author Sauwe
*/
public function composite($width, $height, $color = "black")
{
if ($this->notValid()) {
return false;
}
$width = intval($width);
$height = intval($height);
try {
$im = new Imagick();
$im->newImage($width, $height, new ImagickPixel($color));
$im->setImageFormat('jpg');
foreach ($this->_img_data as $img) {
$data = $img[0];
$x = $img[1];
$y = $img[2];
$opacity = $img[3];
$anchor = $img[4];
if (!method_exists($this, $anchor)) {
continue;
}
$imgc = new Imagick();
$imgc->readImageBlob($data);
$sw = $imgc->getImageWidth();
$sh = $imgc->getImageHeight();
$offset = $this->{$anchor}($width, $height, $sw, $sh, $x, $y);
if ($opacity == 0) {
continue;
}
$imgc->evaluateImage(Imagick::EVALUATE_DIVIDE, 1 / $opacity, Imagick::CHANNEL_ALPHA);
$im->compositeImage($imgc, Imagick::COMPOSITE_DEFAULT, $offset[0], $offset[1]);
}
$this->_img_data = $im->getImageBlob();
return true;
} catch (Exception $e) {
$this->_errno = SAE_ErrUnknown;
$this->_errmsg = $e->getMessage();
return false;
}
}
示例15: _do_background
protected function _do_background($r, $g, $b, $opacity)
{
// Create a RGB color for the background
$color = sprintf('rgb(%d, %d, %d)', $r, $g, $b);
// Create a new image for the background
$background = new Imagick();
$background->newImage($this->width, $this->height, new ImagickPixel($color));
if (!$background->getImageAlphaChannel()) {
// Force the image to have an alpha channel
$background->setImageAlphaChannel(Imagick::ALPHACHANNEL_SET);
}
// Clear the background image
$background->setImageBackgroundColor(new ImagickPixel('transparent'));
// NOTE: Using setImageOpacity will destroy current alpha channels!
$background->evaluateImage(Imagick::EVALUATE_MULTIPLY, $opacity / 100, Imagick::CHANNEL_ALPHA);
// Match the colorspace between the two images before compositing
$background->setColorspace($this->im->getColorspace());
if ($background->compositeImage($this->im, Imagick::COMPOSITE_DISSOLVE, 0, 0)) {
// Replace the current image with the new image
$this->im = $background;
return TRUE;
}
return FALSE;
}