given:
Oracle database with 250 records about participants of science conference (
relarn.samara.ru sorry guys - russian version only).
need:
250 badges with conference logo, participant name and city where he/she from.
solution:
- force designer to make template for badge
- calculate number of badges per sheet and position stuff
- run script
#!/usr/bin/perl
#
# *** - data stripped due to security reason...
#
use DBI;
use GD;
use GD::Text::Wrap;
$ENV{'ORACLE_HOME'} = '***';
$ENV{'NLS_LANG'} = '***';
$ENV{'ORA_NLS'} = '***';
my $font_path = '/usr/share/fonts/ttfonts';
my $gd = GD::Image->new(2135, 3260);
$gd->colorAllocate(255, 255, 255);
open BADGE, "<badge.png";
my $badge = GD::Image->newFromPng(*BADGE);
close BADGE;
my $fio = GD::Text::Wrap->new($gd, width => 800, line_space => 4, colo
+r => $gd->colorAllocate(0, 0, 0), align => 'center');
$fio->font_path($font_path);
$fio->set_font(['verdana'], 70);
my $city = GD::Text::Wrap->new($gd, width => 800, line_space => 10, co
+lor => $gd->colorAllocate(128, 128, 128), align => 'center');
$city->font_path($font_path);
$city->set_font(['verdana'], 40);
my $dbh = DBI->connect('DBI:Oracle:***','***','***');
my $sth = $dbh->prepare_cached("select fname || ' ' || lname, city fro
+m members, cities
where conference_id = ? and member = 'Y' and accepted = 'Y'and members
+.city_id = cities.city_id", undef, 1);
$sth->execute(3);
my $members = $sth->fetchall_arrayref();
my ($m, $i, $j, $n);
my ($f, $c, $d);
my ($left, $top, $right, $bottom);
for ($m = 0; $m < @$members; $m += 10) {
for ($i = 0; $i < 2; $i++) {
for ($j = 0; $j < 5; $j++) {
$gd->copy($badge, $i * 1066, $j * 651, 0, 0, 1067, 652);
$n = $m + $i * 5 + $j;
$f = $$members[$n][0];
$c = $$members[$n][1];
$fio->set(text => $f);
$fio->draw($i * 1066 + 134, $j * 651 + 350);
($left, $top, $right, $bottom) = $fio->get_bounds($i * 10
+66 + 134, $j * 651 + 350);
if ($bottom - ($j * 651 + 350) < 100) {
$gd->copy($badge, $i * 1066, $j * 651, 0, 0, 1067, 6
+52);
$fio->draw($i * 1066 + 134, $j * 651 + 400);
}
print "$f $c ${\($bottom - ($j * 651 + 350))}\n";
$city->set(text => "$c");
$city->draw($i * 1066 + 134, $j * 651 + 555);
}
}
open PNG, ">badges$m.png";
print PNG $gd->png;
close PNG;
print "\n---- badges$m.png written...\n\n";
}
$sth->finish();
$dbh->disconnect();
__END__
yeah! 25 png-files are waiting to be printed!