this example creates a txt file named demo_page.txt background image grows with count number */ ############################################## if ( $_GET[file] ) { $file = $_GET[file]; $back = $_GET[back]; $color = $_GET[color]; #### Make txt file if it doesn't exist if (!file_exists("$file.txt")) { $hits = 1; file_put_contents("$file.txt", $hits); } else { #### If txt file exists get last count and add 1 $hits = file_get_contents("$file.txt"); $hits++; file_put_contents("$file.txt", $hits); } #### Create some objects and image color $image = new Imagick(); $draw = new ImagickDraw(); $pixel = new ImagickPixel($back); #### Font properties $draw->setFont("URW-Palladio-Roman"); $draw->setFontSize(20); $draw->setFillColor($color); #$draw->setStrokeColor($color); #$draw->setStrokeWidth(1.5); $draw->setGravity(Imagick::GRAVITY_CENTER); #### Get font metrics at current settings $metrics = $image->queryFontMetrics($draw, $hits); #### Calculate image size based on font metrics and $border #### Image grows with count number #### Border is space around text $border = 5; $w = $metrics[textWidth]+$border*2; $h = $metrics[textHeight]+$border*2; #### Make background image $image->newimage($w, $h, $pixel); #### Create text and make image $image->annotateImage($draw, 0, 0, 0, $hits); $image->setImageFormat("gif"); #### Output the image with headers header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header('Content-type: image/gif'); echo $image; exit; } else { echo "Can't read data file."; } ?>