I continually have trouble with the invocation of API's and the incorporation of variables into that invocation. For example, this
$image->Draw( fill=>'rgba(100,0,0,0.55)', primitive=>'rectangle', points=>'1460,1060 2060,1180');works just fine. When I start substituting in variables, like this:
$image->Draw( fill=>'rgba(100,0,0,0.55)', primitive=>'rectangle', points=>'$box_left_x,$box_left_y $box_x,$box_y' );I am apparently screwing it up. What is the syntax supposed to be? I have tried single quotes, no quotes, double quotes, etc. I'm sure that it's possible but somehow it feels like the simple things have just eluded me.
And I checked that the variables all have the right value, so that's not it.
The script, in it's entirety...
#!/opt/local/bin/perl use strict; use warnings; use Image::magick; my $image; $image = Image::Magick->new; open( IMAGE, '/Users/coblem/testing/rectangular.jpg' ); $image->Read( file=>\*IMAGE ); # initialize my $i; my $fh; my $mtime; my $color; my $filename; my $fontsize = "18"; my $directory = "/Users/coblem/xplanet/"; my $outfile = "markers/updatelabel"; my @labelpos = (+500, -500); # for each component, we obtain: # - the marker file location and last modified time # - the warning threshold for that component # - the alarm threshold for that component my @config_data = ( ["Quake ", "markers/quake", "3600", "21600", ], ["NORAD ", "satellites/NORAD.tle", "86400", "259200", ], ["Cloud ", "image_files/clouds_4096.jpg", "21600", "86400", ], ["Volcano", "markers/volcano", "86400", "604800", ], ["Fires ", "markers/fires", "86400", "259200", ], ["Storm ", "markers/storm", "21600", "192800", ], ); # processing # draw the semi-transparent box for the label data. This box is locat +ed at a # fixed position on the graphic image. The height of the box is depen +dent on the # number of items to be listed, which the count of items in the config +_data # array. # Then multiply the number of lines by the fontsize (which needs some +padding) my $box_height = ($#config_data + 1) * ($fontsize + 2); my $box_width = 600; my $box_x = 2060; my $box_y = 1180; my $box_left_x = $box_x - $box_width; my $box_left_y = $box_y - $box_height; print "box ", $box_left_x, ",", $box_left_y, " ", $box_x, ",", $box_y, + "\n"; # draw the box and fill it with semi-transparent color (the 'a' part o +f the # rgba value. $image->Draw( fill=>'rgba(100,0,0,0.55)', primitive=>'rectangle', poin +ts=>'$box_left_x,$box_left_y $box_x,$box_y' ); # loop through configuration data items and obtain: # full path to marker file, if it exists. If file does not exist, ret +urn error! # time difference, in days, since script started and last modifed time + (-M[FILENAME]) # use the 3rd and 4th columns as warning and alarm thresholds. If the + time # difference is over the threshold, color code appropriately. open $fh, ">", ($directory . $outfile); my $y = 100; foreach $i ( 0 .. $#config_data ) { $filename = $directory . $config_data[$i][1]; if ( -e $filename) { # test if file exists $mtime = -M $filename; # use -M operator to get +time difference if ( ($mtime * 86400) > $config_data[$i][3]) { # if over +alarm value, -->red $color = 'red'; } elsif ( ($mtime * 86400) > $config_data[$i][2]) { # if ov +er alarm value, -->yellow $color = 'yellow'; } else { $color = 'green'; } # print the label information # at some point, may have to have a routine to calculate the label pos +itions. # right now, it starts in the upper right corner at -35,-1; and drops +10 pixels # for every new line. print $fh ( ($labelpos[0] - ($i*10) ), " ", $labelpos[1], +" ", $config_data[$i][0], " Information Last Updated at: ", scalar lo +caltime((stat($filename))[9]), " color=$color image=none position=pix +el\n"); $image->Annotate( gravity=>'southeast', font=>'Arial', poi +ntsize=>$fontsize, fill=>$color, x=>500, y=>$y, text=>($labelpos[0] - + ($i*10) ), " ", $labelpos[1], " ", $config_data[$i][0], " Informatio +n Last Updated at: ", scalar localtime((stat($filename))[9]) ); $y = $y + $fontsize + 2; } else { print $fh ( ($labelpos[0] - ($i*10) ), " ", $labelpos[1], +" ", "Error! Component \"", $config_data[$i][0], "\" does not exist!! +! color=red image=none position=pixel\n"); $y = $y + $fontsize + 2; } } close $fh; open( IMAGE, ">/Users/coblemtesting/rectangle.jpg" ); $image->write( file=>\*IMAGE, filename=>'/Users/coblem/testing/rectang +le.jpg' ); close (IMAGE);
In reply to Invoking API by mcoblentz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |