GTD Gmail plugin. Javascript.

Image Magick and php

05 Sep 2006

Holy hell the magickwand api for php is cryptic!

For the benefit of all (Me? you?) this is a simple 'watermark' example

///////////////
// php imagemagick test harness
//
// create a watermarked image
///////////////</span>

<!--more-->

//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_OverCompositeOp,  $xoffset, $yoffset);

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