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:
  1. force designer to make template for badge
  2. calculate number of badges per sheet and position stuff
  3. 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!

In reply to 250 badges in a 10 minutes! by Black Greg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.