-blend or -watermark functionality

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
monsters

Watermark with Magick Wand

Post by monsters »

Yeah, what a nightmare figuring that out, could magickwand be any more cryptic..

anyhow, here you go

------------------------
<?php

///////////////
// php imagemagick test harness
//
// create a watermarked image
///////////////

//xoffset of the watermark
$xoffset =10;

//yoffset of the watermark
$yoffset = 10;

//the original image to be watermarked
$originalimage ="original.jpg";

//the watermark to apply
$watermarkimage = "watermark.png";

//top end opacity number (totally transparent)
$opacity0 = @MagickGetQuantumRange();

//bootom opacity (totally visible)
$opacity100 = 0;

//desired opacity percentage
// THIS IS THE ONE TO SET
$opacitypercent = 70;

//gather the actual opacity number
$opacity = $opacity0 - ($opacity0 * $opacitypercent/100 ) ;

//validate the opacity number
if ($opacity > $opacity0){
$opacity = $opacity0;
}elseif ($opacity <0){
$opacity = 0;
}

//initialize the wands
$sourceWand = NewMagickWand();
$compositeWand = NewMagickWand();

//read in the images
@MagickReadImage($compositeWand, $watermarkimage);
@MagickReadImage($sourceWand, $originalimage);

//setting the image index
MagickSetImageIndex($compositeWand, 0);
MagickSetImageType($compositeWand, MW_TrueColorMatteType);

//seting the opacity level
MagickEvaluateImage($compositeWand, MW_SubtractEvaluateOperator, $opacity, MW_OpacityChannel) ;

//combining the images
@MagickCompositeImage($sourceWand, $compositeWand, MW_ScreenCompositeOp, 0, 0);

//print out the image
header("Content-Type: image/jpeg");
MagickEchoImageBlob($sourceWand);

?>
Post Reply