We Recommend

Learning Perl Learning Perl
In this smooth, carefully paced course, a leading Perl trainer teaches you to program in the language that threatens to make C, sed, awk, and the Unix shell obsolete for many tasks. This book is the "official" guide for both formal (classroom) and informal learning. It is fully accessible to the novice programmer.


Posted By

noah on 07/03/07


Tagged

jpg file html images write slideshow create gallery 2003


Versions (?)


Make a list of JPEGs into a slide show


Published in: Perl 


Show jpegs one-per-page on a series of hyperlinked web pages. Purpose was to provide a linear viewing mechanism for jpegs on my Palm Tungsten C.

  1. #! /usr/bin/perl -w
  2. use strict;
  3.  
  4. ############################################################
  5. # #
  6. # #
  7. # #
  8. # NOAH SUSSMAN #
  9. # #
  10. # showserial.pl #
  11. # #
  12. # Created 10/8/3 at 1.41am #
  13. # #
  14. # Show jpegs one-per-page on a series of hyperlinked #
  15. # web pages. Purpose is to provide a good _linear_ #
  16. # viewing mechanism for jpegs on the palm. #
  17. # Adapted from showsm.pl #
  18. # #
  19. # #
  20. ############################################################
  21.  
  22.  
  23. my @images;
  24.  
  25. while (<*\.jp*>) {
  26. push @images, $_; #read image filenames into a list
  27. }
  28.  
  29. shift @images; #first image is never the subject of a "next" hyperlink
  30.  
  31. while (<*\.jp*>) { #regex captures any filename with extension beginning "JP"
  32.  
  33. my $next_file;
  34. $next_file = $images[0]; #read the next filename into $next_file
  35. shift @images; #manually discard the value we just read into $next_file
  36.  
  37. my $out="$_";
  38. $out =~ s/jpeg/html/gio;
  39. open OUT, ">$out" or die "Cannot open $out for write :$!";
  40.  
  41.  
  42. if ($next_file){
  43. #print $next_file;
  44. $next_file =~ s/jpeg/html/gio;
  45. print OUT "<a href=\"$next_file\">";
  46. }
  47.  
  48. print OUT "<html><head><title>$_</title></head><body>\n";
  49. print OUT "<img src=\"$_\" >\n"; #an image tag points to each file name
  50. print OUT "</body></html>";
  51.  
  52.  
  53. if ($next_file){
  54. print OUT "</a>";
  55. }
  56. }

Report this snippet 

You need to login to post a comment.