Posted By

iblis on 08/06/07


Tagged

image pdf convert


Versions (?)

Bundle a bunch of images into a pdf document


 / Published in: Perl
 

Requires PerlMagick.

  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Image::Magick;
  4.  
  5. # Bundle a bunch of images into a pdf document
  6. #
  7. # Matches files in given directory according to given regex
  8. # and wraps them in a pdf document
  9.  
  10. die "Usage: $0 path regex [output_filename]\n" if (! defined $ARGV[1]) ;
  11. my $path = shift;
  12. my $regex = shift;
  13. my $output = (defined $ARGV[0]) ? shift : 'bundle.pdf';
  14.  
  15. # open path or die
  16. opendir DIR, $path
  17. or die "Can't open $path : $!\n";
  18.  
  19. # build a list of files with full path matching the regex
  20. my @filelist = map {$path . '/' . $_}
  21. grep { -f "$path/$_" && /$regex/}
  22. readdir DIR;
  23.  
  24. # do not proceed further if file list empty
  25. exit if (!defined $filelist[0]);
  26.  
  27. # call image magick
  28. my $magick = new Image::Magick(format=>"pdf");
  29. my $status;
  30. $status = $magick->Read(@filelist) and warn "Read failed: $status";
  31. $status = $magick->Write("pdf:$output") and warn "Write failed: $status";

Report this snippet  

You need to login to post a comment.