/** * * @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; }
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; }
/** * 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; }
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; } }
/** * 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(); }
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); }
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; }
/** * {@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(); }
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); } }
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; }
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; }
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); } }
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; }
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(); }
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; }
function createMask($firstPicture, $twoPicture, $mask, $maskX, $masky, $x, $y) { $img = new Imagick($firstPicture); $mask = new Imagick($mask); $width = $mask->getImageWidth(); $height = $mask->getImageHeight(); $img->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1); $img->compositeImage($mask, Imagick::COMPOSITE_DSTIN, $maskX, $masky); header("Content-Type: image/jpeg"); $img2 = new Imagick('goodMasks.jpg'); $img2->compositeImage($img, $img->getImageCompose(), $x, $y); echo $img2; }
public function resize($size) { // Phwittr(Twitter)用にcropに変更 $imagick = $this->imagick; $imagick->cropThumbnailImage($size, $size); $x = ($size - $imagick->getImageWidth()) / 2; $y = ($size - $imagick->getImageHeight()) / 2; $buf = new Imagick(); $buf->newImage($size, $size, new ImagickPixel("#fff"), $this->type); $buf->compositeImage($imagick, Imagick::COMPOSITE_OVER, $x, $y); $this->imagick = $buf; return $this; }
/** * @param $image * @return Pimcore_Image_Adapter_Imagick */ public function applyMask($image) { $image = ltrim($image, "/"); $image = PIMCORE_DOCUMENT_ROOT . "/" . $image; if (is_file($image)) { $this->resource->setImageMatte(1); $newImage = new Imagick(); $newImage->readimage($image); $newImage->resizeimage($this->getWidth(), $this->getHeight(), Imagick::FILTER_UNDEFINED, 1, false); $this->resource->compositeImage($newImage, Imagick::COMPOSITE_DSTIN, 0, 0); } $this->reinitializeImage(); return $this; }
function perspective($firstPicture, $twoPicture, $pointTLX, $pointTLY, $pointBLX, $pointBLY, $pointTRX, $pointTRY, $pointBRX, $pointBRY) { $imagick = new \Imagick(realpath($firstPicture)); $points = array(array('x' => $pointTLX, 'y' => $pointTLY), array('x' => $pointBLX, 'y' => $pointBLY), array('x' => $pointTRX, 'y' => $pointTRY), array('x' => $pointBRX, 'y' => $pointBRY)); $geometry = $imagick->getImageGeometry(); $controlPoints = array(0, 0, $points[0]['x'], $points[0]['y'], 0, $geometry['height'], $points[1]['x'], $points[1]['y'], $geometry['width'], 0, $points[2]['x'], $points[2]['y'], $geometry['width'], $geometry['height'], $points[3]['x'], $points[3]['y']); $imagick->distortImage(Imagick::DISTORTION_AFFINE, $controlPoints, true); header("Content-Type: image/jpg"); $img2 = new Imagick($twoPicture); $imagick->thumbnailImage(140, 140); //$img2->compositeImage($imagick, $imagick->getImageCompose(), 155, 290); $img2->compositeImage($imagick, $imagick->getImageCompose(), $pointTLX, $pointTRY); echo $img2; }
function using_imagick() { global $image, $mask, $clut, $final, $qual; $im = new Imagick($image); # Apply color lookup table $im->clutImage(new Imagick($clut)); # Apply transparency mask $im->compositeImage(new Imagick($mask), imagick::COMPOSITE_COPYOPACITY, 0, 0); # Save the image $im->setCompressionQuality($qual); $im->setImageDepth(8); $im->setFormat("png"); $im->writeImage($final); }
/** * 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); }
function image($product_id = 0, $view = 'front', $index = 0) { $product_id = (int) $product_id; $index = (int) $index; if ($product_id == 0) { return false; } $this->load->driver('cache'); if ($this->cache->file->get('product-img-' . $product_id . '-' . $view . '-' . $index) == false) { // load product design $this->load->model('product_m'); $product = $this->product_m->getProductDesign($product_id); if (count($product)) { $this->load->helper('product'); $help_product = new helperProduct(); $design = $help_product->getDesign($product); } else { return false; } $design = json_decode(json_encode($design), true); if (empty($design[$view][$index])) { return false; } $string = str_replace("'", '"', $design[$view][$index]); $string = str_replace('px"', '"', $string); $img = new Imagick(); $img->newImage(500, 500, new ImagickPixel('transparent')); $img->setImageFormat('png'); $design = json_decode($string, true); $n = count($design) - 1; for ($i = $n; $i >= 0; $i--) { $image = $design[$i]; if ($image['id'] == 'area-design') { continue; } $file = ROOTPATH . DS . str_replace('/', DS, $image['img']); $newfile = new Imagick($file); $newfile->resizeImage($image['width'], $image['height'], Imagick::FILTER_LANCZOS, 1); $img->compositeImage($newfile, Imagick::COMPOSITE_DEFAULT, $image['left'], $image['top']); } $thumbnail = $img->getImageBlob(); $this->cache->file->save('product-img-' . $product_id . '-' . $view . '-' . $index, base64_encode($thumbnail), 300000); } else { $img = $this->cache->file->get('product-img-' . $product_id . '-' . $view . '-' . $index); $thumbnail = base64_decode($img); } header("Content-Type: image/png"); echo $thumbnail; }
/** * Performs optimized gradient fill for non-opaque linear gradients * * @param Linear $fill */ private function applyFastLinear(Linear $fill) { $gradient = new \Imagick(); $size = $this->getSize(); $color = sprintf('gradient:%s-%s', (string) $fill->getStart(), (string) $fill->getEnd()); if ($fill instanceof Horizontal) { $gradient->newPseudoImage($size->getHeight(), $size->getWidth(), $color); $gradient->rotateImage(new \ImagickPixel(), 90); } else { $gradient->newPseudoImage($size->getWidth(), $size->getHeight(), $color); } $this->imagick->compositeImage($gradient, \Imagick::COMPOSITE_OVER, 0, 0); $gradient->clear(); $gradient->destroy(); }
public function watermark($file, $mark_image, $set) { $image = new Imagick(); $image->readImage($file); $watermark = new Imagick(); $watermark->readImage($mark_image); $opacity = isset($set['wm_opacity']) ? (int) $set['wm_opacity'] : 100; $watermark->setImageOpacity($opacity / 100); $image->compositeImage($watermark, imagick::COMPOSITE_DEFAULT, $set['dest_x'], $set['dest_y']); $image->writeImage(); $image->clear(); $image->destroy(); $watermark->clear(); $watermark->destroy(); }
/** * @param $image * @return self */ public function applyMask($image) { $this->preModify(); $image = ltrim($image, "/"); $image = PIMCORE_DOCUMENT_ROOT . "/" . $image; if (is_file($image)) { $this->resource->setImageMatte(1); $newImage = new \Imagick(); $newImage->readimage($image); $newImage->resizeimage($this->getWidth(), $this->getHeight(), \Imagick::FILTER_UNDEFINED, 1, false); $this->resource->compositeImage($newImage, \Imagick::COMPOSITE_COPYOPACITY, 0, 0, \Imagick::CHANNEL_ALPHA); } $this->postModify(); $this->setIsAlphaPossible(true); return $this; }
protected function tile($tile, $width, $height) { $canvas = new Imagick(); $canvas->newImage($width, $height, 'transparent'); list($tileWidth, $tileHeight) = $this->dimensions($tile); $x = $y = 0; while ($y <= $height) { while ($x <= $width) { $canvas->compositeImage($tile, Imagick::COMPOSITE_DEFAULT, $x, $y, Imagick::CHANNEL_ALL); $x += $tileWidth; } $y += $tileHeight; $x = 0; } return $canvas; }
/** * @param string $file * @param int $offsetX * @param int $offsetY * @param float $opacity * * @return static * @throws \ManaPHP\Image\Adapter\Exception */ public function watermark($file, $offsetX = 0, $offsetY = 0, $opacity = 1.0) { $watermark = new \Imagick($this->alias->resolve($file)); if ($watermark->getImageAlphaChannel() === \Imagick::ALPHACHANNEL_UNDEFINED) { $watermark->setImageOpacity($opacity); } if ($watermark->getNumberImages() !== 1) { throw new ImagickException('not support multiple iterations: `:file`', ['file' => $file]); } if (!$this->_image->compositeImage($watermark, \Imagick::COMPOSITE_OVER, $offsetX, $offsetY)) { throw new ImagickException('Imagick::compositeImage Failed'); } $watermark->clear(); $watermark->destroy(); return $this; }
/** * @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(); } }
function __construct($src, $dst, $flatten) { parent::__construct($dst); if ($src instanceof Strass_Vignette_Imagick) { $image = $src->image; } else { $image = new Imagick(); $image->setBackgroundColor(new ImagickPixel('transparent')); $image->readImage($src); if ($flatten) { $photo = $image; $image = new Imagick(); $image->newImage($photo->getImageWidth(), $photo->getImageHeight(), "white"); $image->compositeImage($photo, Imagick::COMPOSITE_OVER, 0, 0); } } $this->image = $image; }
/** * @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(); } }