#!/usr/bin/perl -w # Example 3-1. Hello World in ImageMagick use strict; use Image::Magick; # Create a new image my $image = new Image::Magick; $image->Set(size => '401x201'); my $status = $image->Read(filename => 'xc:white'); warn "$status" if $status; # Draw the field of circles my ($x1, $y1, $x2, $y2); for my $i (0..10) { for my $j (0..5) { my $r = rand(25)+1; # random radius # The center of the circle is x1,y1 # x2,y2 is a point on the circle ($x1, $y1, $x2, $y2) = ($i*40, $j*40, $i*40, $j*40+$r); $image->Draw( primitive=>'Circle', points=> "$x1,$y1 $x2,$y2", stroke=>'red', fill => '#FF0000', antialias=>1, linewidth => 1 ); } } # Draw the text my ($x, $y) = (40, 120); $image->Annotate(font => '@arial.ttf', pointsize => 64, stroke => '#000000', fill => 'black', text => "Hello World", geometry=> "+$x+$y" ); # Get the dimensions of the rendered text my ($w, $h, $ascend, $descend, $text_w, $text_h, $max) = $image->QueryFontMetrics(font => '@arial.ttf', pointsize => 64, text => "Hello World"); # Calculate the bounding box ($x1, $y1, $x2, $y2) = ($x-10, $y-$text_h-$descend-10, $x+$text_w+10, $y-$descend+10); # Draw a black rectangle $image->Draw(primitive => 'Rectangle', points => "$x1,$y1 $x2,$y2", stroke => 'black', ); # Write as a PNG $image->Write('png:out.png'); undef $image;