Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
  1. insert a CD in your cd-reader
  2. be sure your internet connection is up
  3. run this script
  4. print the .pdf file it will create
  5. use scissors
  6. feel guilty ;)

Related code:

Here the code:

#!/usr/bin/perl # cddb_cover.pl - 17/9/2001 # by Stefano Rodighiero # http://larsen.perlmonk.org use strict; # This script runs only under Linux (tested), # SunOS or NetBSD because it does use CDDB_get qw/get_cddb/; # "This module/script gets the CDDB info for # an audio cd. You need LINUX, SUNOS or NETBSD, # a cdrom drive and an active # internet connection in order to do that" # ( CDDB_get docs ) use PDF::Create; # A4 are 210x297 mm use constant A4_WIDTH => 612; use constant A4_HEIGHT => 792; use constant A4_BOX => [0, 0, 612, 792]; # A CD cover is 12cm side... use constant CD_WIDTH => 350; my %font_size = ( Small => 10, Medium => 15, Large => 20, ); my %config_cddb = ( CDDB_HOST => 'freedb.freedb.org', CDDB_PORT => '8880', CDDB_MODE => 'cddb', CD_DEVICE => '/dev/cdrom', input => 0 ); my %cd = get_cddb( \%config_cddb ); my $pdf = new PDF::Create( filename => $ARGV[0] || 'cover.pdf', Version => 1.2, PageMode => 'UseNone', Author => '', Creator => '', Title => 'Copertina' ); my $root = $pdf->new_page( Mediabox => [ A4_BOX ] ); my $font = $pdf->font( Subtype => 'Type1', Encoding => 'WinAnsiEncoding', BaseFont => 'Helvetica' ); my $page = $root->new_page; my $cover = { # Where front has to be put on the page? front_corner_x => 100, front_corner_y => 10, # The same for the back back_corner_x => 100, back_corner_y => 10 + CD_WIDTH + 10, }; draw_front( $page, \%cd ); draw_back( $page, \%cd ); $pdf->close; sub draw_front { my $page = shift; my $cd = shift; draw_CD_box( $page, $cover->{ 'front_corner_x' }, $cover->{ 'front_c +orner_y' }, "Front" ); $page->string( $font, $font_size{'Medium'}, $cover->{'front_corner_x'} + 5, $cover->{'front_corner_y'} + CD_WIDTH - $font_size{'Medium'}, $cd->{'artist'} ); # print "$cd->{'artist'}\n"; $page->string( $font, $font_size{'Large'}, $cover->{'front_corner_x'} + 5, $cover->{'front_corner_y'} + CD_WIDTH - 5 - $font_size{'Medium'} - +$font_size{'Large'}, $cd->{'title'} ); # print "$cd->{'title'}\n"; } sub draw_back { my $page = shift; my $cd = shift; draw_CD_box( $page, $cover->{ 'back_corner_x' }, $cover->{ 'back_cor +ner_y' }, "Back" ); my $initial_pos = $cover->{'back_corner_y'} + ($font_size{'Small'} * + $cd->{'tno'}); my $counter = 1; foreach my $title ( @{ $cd->{'track'}} ) { $page->string( $font, $font_size{'Small'}, $cover->{'back_corner_x'} + 5, $initial_pos - $font_size{'Small'} + * ($counter - 1), "$counter. " . $title ); ++$counter; # print "$counter. $title\n"; } } # Draw CD bounding box sub draw_CD_box { my $page = shift; my ($corner_x, $corner_y, $str) = @_; my @corner = ( [$corner_x, $corner_y], [$corner_x + CD_WIDTH, $corner_y], [$corner_x + CD_WIDTH, $corner_y + CD_WIDTH], [$corner_x, $corner_y + CD_WIDTH], [$corner_x, $corner_y] # yes, it's the first repeated. see below ); foreach( 0..3 ) { $page->line( @{$corner[$_]}, @{$corner[$_+1]} ); } # Put a string near the right-upper corner if ( $str ) { $page->string( $font, $font_size{'Small'}, $corner_x + CD_WIDTH + 5, $corner_y + CD_WIDTH - $font_size{'Smal +l'}, $str ); } }

Update: some minor editing (indentation, paragraph tag)
Update: added <readmore>, as suggested by Petruchio


In reply to Audio CD covers by larsen

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [Corion]: Tabish: What are "tow" packages? Maybe you want to use PAR::Packer to copy them and your main program into one (ugly) script for distribution?

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (7)
    As of 2017-12-11 09:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What programming language do you hate the most?




















      Results (288 votes). Check out past polls.

      Notices?