On Mon, 1 Dec 2008 16:37:22 -0500 (EST) "Jim Shupert, Jr." <[EMAIL PROTECTED]> wrote:
> > >so here is a complicated one -- well , it's complicated for me > >I wish to do an sql query and shove the returns as vars into a convert on >a jpg. Here is how you would do it in Perl. The hardest part, (but relatively easy with perl) is the DB connection. In Perl, you have a basic Mysql driver, and an easy access layer on top, called DBI. DBI allows you to access any type of sql db with the same syntax. You can google for "Perl mysql" for many code examples. In the following, I just make a white graphic (instead of reading in a file), then use Annotate. See http://imagemagick.org/script/perl-magick.php for all the Annotate options. ######################################### #!/usr/bin/perl use warnings; use strict; use Image::Magick; use DBI; use POSIX 'strftime'; # how to access the Mysql db #my $dbh = DBI->connect('DBI:mysql:databasename', # 'user','password') or die "Couldn't open database: ". DBI->errstr . "\n"; #my $sth = $dbh->prepare("SELECT date_format(?,'%V')"); #my $rc = $sth->execute('2003-01-5'); #my @temp = $sth->fetchrow_array; # results returned as an array, for example: # print "WEEK: $temp[0]\n"; # print "NAME: $temp[1]\n"; # assume you got these values my $week = 51; my $name = 'FooMaster'; my $time = strftime "%a %b %e %H:%M:%S %Y", localtime; ############################################################ # By the way if your week starts on Monday instead of # Sunday use this: # my $sth = $dbh->prepare("SELECT date_format(?,'%v')"); ############################################################ my $image = Image::Magick->new; $image->Set(size=>'612x792'); # US letter 8.5 x 11 inches my $rc = $image->Read("xc:white"); $image->Annotate(pointsize => 36, fill => '#000000ff', #last 2 digits transparency in hex ff=max text => "Week: $week", gravity => 'NorthWest', x => 100, y => 100, ); $image->Annotate(pointsize => 24, fill => '#ff0000ff', #last 2 digits transparency in hex ff=max text => "Name: $name", style => 'Italic', gravity => 'NorthWest', x => 100, y => 200, ); $image->Annotate(pointsize => 18, fill => '#ffff00ff', #last 2 digits transparency in hex ff=max text => "Time: $time", gravity => 'NorthWest', x => 100, y => 300, undercolor => '#00000066' ); $image->Write("$0.png"); exit; __END__ zentara -- I'm not really a human, but I play one on earth. http://zentara.net/Remember_How_Lucky_You_Are.html _______________________________________________ Magick-users mailing list [email protected] http://studio.imagemagick.org/mailman/listinfo/magick-users
