本文整理匯總了PHP中Imagick::compositeImage方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::compositeImage方法的具體用法?PHP Imagick::compositeImage怎麽用?PHP Imagick::compositeImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::compositeImage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fx
/**
*
* @param mixed color
* @param float opacity
*/
public function fx($color = 'black', $opacity = 0.3)
{
$this->im->setImageFormat('png');
$reflection = $this->im->clone();
$reflection->flipImage();
$gradient = new Imagick();
$gradient->newPseudoImage($reflection->getImageWidth(), $reflection->getImageHeight(), "gradient:transparent-{$color}");
$reflection->compositeImage($gradient, imagick::COMPOSITE_OVER, 0, 0);
$reflection->setImageOpacity($opacity);
$canvas = new Imagick();
$canvas->newImage($this->im->getImageWidth(), $this->im->getImageHeight() * 2, $color, "png");
$canvas->compositeImage($this->im, imagick::COMPOSITE_OVER, 0, 0);
$canvas->compositeImage($reflection, imagick::COMPOSITE_OVER, 0, $this->im->getImageHeight());
return $canvas;
}
示例2: multiply
function multiply($firstPicture, $twoPicture, $x, $y)
{
$img = new Imagick($firstPicture);
$img->thumbnailImage(140, 140);
$shadow = $img->clone();
$shadow->setImageBackgroundColor(new ImagickPixel('black'));
//color shadow
$shadow->shadowImage(80, 3, 5, 5);
//create shadow
$shadow->compositeImage($img, Imagick::COMPOSITE_OVER, 0, 0);
header("Content-Type: image/jpeg");
$img2 = new Imagick($twoPicture);
$img2->compositeImage($shadow, $shadow->getImageCompose(), $x, $y);
echo $img2;
}
示例3: execute
/**
* Reduces colors of a given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$count = $this->argument(0)->value();
$matte = $this->argument(1)->value();
// get current image size
$size = $image->getSize();
// build 2 color alpha mask from original alpha
$alpha = clone $image->getCore();
$alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA);
$alpha->transparentPaintImage('#ffffff', 0, 0, false);
$alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA);
$alpha->negateImage(false);
if ($matte) {
// get matte color
$mattecolor = $image->getDriver()->parseColor($matte)->getPixel();
// create matte image
$canvas = new \Imagick();
$canvas->newImage($size->width, $size->height, $mattecolor, 'png');
// lower colors of original and copy to matte
$image->getCore()->quantizeImage($count, \Imagick::COLORSPACE_RGB, 0, false, false);
$canvas->compositeImage($image->getCore(), \Imagick::COMPOSITE_DEFAULT, 0, 0);
// copy new alpha to canvas
$canvas->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
// replace core
$image->setCore($canvas);
} else {
$image->getCore()->quantizeImage($count, \Imagick::COLORSPACE_RGB, 0, false, false);
$image->getCore()->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
}
return true;
}
示例4: watermarkPrint_imagick
private function watermarkPrint_imagick($src, $watermark, $dest_x, $dest_y, $quality, $transparency, $watermarkImgInfo)
{
try {
// Open the original image
$img = new Imagick($src);
// Open the watermark
$watermark = new Imagick($watermark);
// Set transparency
if (strtoupper($watermark->getImageFormat()) !== 'PNG') {
$watermark->setImageOpacity($transparency / 100);
}
// Overlay the watermark on the original image
$img->compositeImage($watermark, imagick::COMPOSITE_OVER, $dest_x, $dest_y);
// Set quality
if (strtoupper($img->getImageFormat()) === 'JPEG') {
$img->setImageCompression(imagick::COMPRESSION_JPEG);
$img->setCompressionQuality($quality);
}
$result = $img->writeImage($src);
$img->clear();
$img->destroy();
$watermark->clear();
$watermark->destroy();
return $result ? true : false;
} catch (Exception $e) {
return false;
}
}
示例5: apply
/**
* Applies the effect.
*/
public function apply()
{
if (!method_exists($this->_image->imagick, 'polaroidImage') || !method_exists($this->_image->imagick, 'trimImage')) {
throw new Horde_Image_Exception('Your version of Imagick is not compiled against a recent enough ImageMagick library to use the PolaroidImage effect.');
}
try {
// This determines the color of the underlying shadow.
$this->_image->imagick->setImageBackgroundColor(new ImagickPixel($this->_params['shadowcolor']));
$this->_image->imagick->polaroidImage(new ImagickDraw(), $this->_params['angle']);
// We need to create a new image to composite the polaroid over.
// (yes, even if it's a transparent background evidently)
$size = $this->_image->getDimensions();
$imk = new Imagick();
$imk->newImage($size['width'], $size['height'], $this->_params['background']);
$imk->setImageFormat($this->_image->getType());
$result = $imk->compositeImage($this->_image->imagick, Imagick::COMPOSITE_OVER, 0, 0);
$this->_image->imagick->clear();
$this->_image->imagick->addImage($imk);
} catch (ImagickPixelException $e) {
throw new Horde_Image_Exception($e);
} catch (ImagickDrawException $e) {
throw new Horde_Image_Exception($e);
} catch (ImagickException $e) {
throw new Horde_Image_Exception($e);
}
$imk->destroy();
}
示例6: Imagick
function apply_mask($image_src_path, $mask_path, $image_dest_path)
{
$src = new Imagick($image_src_path);
$mask = new Imagick($mask_path);
$src->compositeImage($mask, Imagick::COMPOSITE_DEFAULT, 0, 0);
$src->writeImage($image_dest_path);
}
示例7: Imagick
function page_testfonts()
{
//load background
$im = new Imagick();
$im->newimage(800, 10000, 'lightgray');
$y = 10;
$i = 1;
foreach ($im->queryFonts() as $font) {
$insert_image = new Imagick();
$insert_image->newImage(600, 30, 'whitesmoke');
$insert_image->setImageFormat("png");
$draw = new ImagickDraw();
$draw->setFont($font);
$draw->setFontSize(25);
$draw->setFillColor(new ImagickPixel('black'));
$draw->setgravity(imagick::GRAVITY_NORTH);
$insert_image->annotateImage($draw, 0, 0, 0, $i . '.' . $font);
$im->compositeImage($insert_image, $insert_image->getImageCompose(), 100, $y);
$y += 30;
$i++;
}
$im->setImageFormat('jpg');
header('Content-Type: image/jpg');
echo $im;
}
示例8: watermark
/**
* {@inheritdoc}
*/
public function watermark($file, $position = Image::WATERMARK_TOP_LEFT, $opacity = 100)
{
$watermark = new Imagick($file);
$watermarkW = $watermark->getImageWidth();
$watermarkH = $watermark->getImageHeight();
if ($opacity < 100) {
$watermark->evaluateImage(Imagick::EVALUATE_MULTIPLY, $opacity / 100, Imagick::CHANNEL_ALPHA);
}
// Position the watermark.
switch ($position) {
case Image::WATERMARK_TOP_RIGHT:
$x = $this->image->getImageWidth() - $watermarkW;
$y = 0;
break;
case Image::WATERMARK_BOTTOM_LEFT:
$x = 0;
$y = $this->image->getImageHeight() - $watermarkH;
break;
case Image::WATERMARK_BOTTOM_RIGHT:
$x = $this->image->getImageWidth() - $watermarkW;
$y = $this->image->getImageHeight() - $watermarkH;
break;
case Image::WATERMARK_CENTER:
$x = $this->image->getImageWidth() / 2 - $watermarkW / 2;
$y = $this->image->getImageHeight() / 2 - $watermarkH / 2;
break;
default:
$x = 0;
$y = 0;
}
$this->image->compositeImage($watermark, Imagick::COMPOSITE_OVER, $x, $y);
$watermark->destroy();
}
示例9: addWatermark
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);
}
}
示例10: save
protected function save($path)
{
$pathinfo = pathinfo($path);
if (!file_exists($pathinfo['dirname'])) {
mkdir($pathinfo['dirname'], 0777, true);
}
try {
$image = new \Imagick($this->source);
$image->thumbnailImage($this->width, $this->height, true);
if ($this->color) {
$thumb = $image;
$image = new \Imagick();
$image->newImage($this->width, $this->height, $this->color, $pathinfo['extension']);
$size = $thumb->getImageGeometry();
$x = ($this->width - $size['width']) / 2;
$y = ($this->height - $size['height']) / 2;
$image->compositeImage($thumb, \imagick::COMPOSITE_OVER, $x, $y);
$thumb->destroy();
}
$image->writeImage($path);
$image->destroy();
} catch (\Exception $e) {
}
return $this;
}
示例11: resizeTo
public function resizeTo($width, $height)
{
if (osc_use_imagick()) {
$bg = new Imagick();
$bg->newImage($width, $height, 'white');
$this->im->thumbnailImage($width, $height, true);
$geometry = $this->im->getImageGeometry();
$x = ($width - $geometry['width']) / 2;
$y = ($height - $geometry['height']) / 2;
$bg->compositeImage($this->im, imagick::COMPOSITE_OVER, $x, $y);
$this->im = $bg;
} else {
$w = imagesx($this->im);
$h = imagesy($this->im);
if ($w / $h >= $width / $height) {
//$newW = $width;
$newW = $w > $width ? $width : $w;
$newH = $h * ($newW / $w);
} else {
//$newH = $height;
$newH = $h > $height ? $height : $h;
$newW = $w * ($newH / $h);
}
$newIm = imagecreatetruecolor($width, $height);
//$newW, $newH);
imagealphablending($newIm, false);
$colorTransparent = imagecolorallocatealpha($newIm, 255, 255, 255, 127);
imagefill($newIm, 0, 0, $colorTransparent);
imagesavealpha($newIm, true);
imagecopyresampled($newIm, $this->im, ($width - $newW) / 2, ($height - $newH) / 2, 0, 0, $newW, $newH, $w, $h);
imagedestroy($this->im);
$this->im = $newIm;
}
return $this;
}
示例12: softThumb
public function softThumb($width, $height, $path, $bg = 'transparent')
{
if ($this->originImage) {
echo "\nWrite image to `{$path}`\n";
$resizeParams = $this->getSizes($width, $height);
$overlay = clone $this->originImage;
$overlay->scaleImage($resizeParams['width'], $resizeParams['height']);
$overlayGeo = $overlay->getImageGeometry();
if ($overlayGeo['width'] > $overlayGeo['height']) {
$resizeParams['top'] = ($height - $overlayGeo['height']) / 2;
$resizeParams['left'] = 0;
} else {
$resizeParams['top'] = 0;
$resizeParams['left'] = ($width - $overlayGeo['width']) / 2;
}
$thumb = new \Imagick();
$thumb->newImage($width, $height, $bg);
$thumb->setImageFormat("png");
$thumb->setCompression(\Imagick::COMPRESSION_ZIP);
$thumb->setImageCompressionQuality(0);
$thumb->compositeImage($overlay, \Imagick::COMPOSITE_DEFAULT, $resizeParams['left'], $resizeParams['top']);
$thumb->writeImageFile(fopen($path, "wb"));
$thumb->destroy();
} else {
throw new \Exception("As first You must load image", 404);
}
}
示例13: overlay
public function overlay($layer, $x = 0, $y = 0)
{
$layerCs = $layer->image->getImageColorspace();
$layer->image->setImageColorspace($this->image->getImageColorspace());
$this->image->compositeImage($layer->image(), $this->compositionMode, $x, $y);
$layer->image->setImageColorspace($layerCs);
return $this;
}
示例14: renderFontEffect
function renderFontEffect()
{
$canvas = new \Imagick();
$canvas->newPseudoImage(500, 300, "canvas:none");
$canvas->setImageFormat('png');
$shadow = clone $canvas;
$text = clone $canvas;
drawText($text);
drawText($shadow, true);
$edge = getSilhouette($text);
$kernel = \ImagickKernel::fromBuiltIn(\Imagick::KERNEL_OCTAGON, "2");
$edge->morphology(\Imagick::MORPHOLOGY_EDGE_IN, 1, $kernel);
$edge->compositeImage($text, \Imagick::COMPOSITE_ATOP, 0, 0);
$canvas->compositeImage($shadow, \Imagick::COMPOSITE_COPY, 0, 0);
$canvas->compositeImage($text, \Imagick::COMPOSITE_ATOP, 0, 0);
header("Content-Type: image/png");
echo $canvas->getImageBlob();
}
示例15: inscribeImageIntoCanvas
private function inscribeImageIntoCanvas(\Imagick $image) : \Imagick
{
$dimensions = $image->getImageGeometry();
$x = (int) round(($this->width - $dimensions['width']) / 2);
$y = (int) round(($this->height - $dimensions['height']) / 2);
$canvas = new \Imagick();
$canvas->newImage($this->width, $this->height, $this->backgroundColor, $image->getImageFormat());
$canvas->compositeImage($image, \Imagick::COMPOSITE_OVER, $x, $y);
return $canvas;
}
開發者ID:lizards-and-pumpkins,項目名稱:lib-image-processing-imagick,代碼行數:10,代碼來源:ImageMagickInscribeStrategy.php