Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-20 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found