This script will print a watermark on the middle of an image. The width of the watermark will depend on the width of the image.
<?php
$objImage = new Imagick( 'path/to/image.jpg' );
$imgSize = $objImage->getImageGeometry();
$imgWidth = $imgSize['width'];
$imgHeight = $imgSize['height'];
$objText = new ImagickDraw();
$objText->setFillColor( new ImagickPixel('grey') );
$objText->setFillAlpha( 0.2 );
$objText->setGravity( Imagick::GRAVITY_NORTHWEST );
$textProperties = array( 'textWidth' => 0 );
$textDesiredWidth = intval( $imgWidth * 0.9 );
$fontSize = 0;
$text = $_SERVER['SERVER_NAME'];
while ( $textProperties['textWidth'] <= $textDesiredWidth ) {
$objText->setFontSize( $fontSize );
$textProperties = $objImage->queryFontMetrics( $objText, $text );
$fontSize++;
}
$watermarkPosX = intval( ($imgWidth - $textProperties['textWidth']) / 2 );
$watermarkPosY = floor( ($imgHeight - $textProperties['textHeight']) / 2 );
$objImage->annotateImage( $objText, $watermarkPosX, $watermarkPosY, 0, $text );
header( 'Content-Type: image/jpeg' );
echo $objImage;
?>