THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.
I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.
IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.
// Defaults
$image = '$output14';
$gravity = '-gravity Southeast';
$option = '-pointsize 50 -background "#00000000" -fill';
$text = "Rubblewebs";
// Create the label to get its size
$cmd = "$option white label:\"Test\" -format %wx%h";
$i = exec("convert $cmd info:");
// Find the averidge colour below the label position
$cmd = "$image $gravity -crop $i+0+0 -format \"%[fx:(mean<0.5)?1:0]\" ";
$j = exec("convert $cmd info:");
// Set the colour for the label
if ( $j == 1 ){ $j = '255'; } else { $j = '000'; }
// watermark the image
$cmd = "$option rgb($j,$j,$j) label:\"$text\" $image -reverse -compose over $gravity -geometry +22+22 -composite";
exec("convert $cmd colour_sensative_watermark.jpg");
Watermark colour depends on the background colour.
Based on an example by whugemann on the Imagemagick forum.