Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; # ----------- # 'split' written by David Wakeman # and distributed using the GPL license. # # Created 03.28.2002 on planet earth. # # Use at your own risk. I am not responsible # for any loss of data, loss of life, computer # equipment explosion, divorce, dropped food # or anything else that you may think happened # because of this program. # # Enjoy! # # # # ----------- use Imager; use IO::File; use Getopt::Long; use File::Spec::Win32; use File::DosGlob 'glob'; use Time::HiRes qw( gettimeofday ); # ----------- # command-line args (html on|off and image list) my ($hoff, @images); GetOptions( "hoff" => \$hoff ); if (@ARGV) { foreach (@ARGV) { push(@images, $_); } } else { @images = glob "*.jpg"; } my $imageCount = @images; unless ($imageCount > 0) { print "No images found!\n\n"; &usage; } &process; # ----------- # main sub sub process { my $count = 0; my $message = "Cannot crop image"; open(LOG, "+>splitlog.txt") || die "Can't open log: ($!)\n"; my ($secs, $msecs) = gettimeofday; foreach (@images) { $_ =~ /(.*?).jpg/i; my $pic = $1; # ----------- # start our image object my $img = Imager->new(); $img->open(file => "$_"); # ----------- # check image size my $imgHeight = $img->getheight(); my $imgWidth = $img->getwidth(); if ($imgHeight != 300 && $imgWidth != 654) { print LOG "$_ does not conform to x,y requirements - skipp +ed.\n"; next; } # image is good so increment $count++; # ----------- # crop image 6 times my $newImage01 = $img->crop( left=>0 , right=>218, top=>0 , +bottom=>150 ) || die "$message: ($!)\n"; my $newImage02 = $img->crop( left=>218, right=>437, top=>0 , +bottom=>150 ) || die "$message ($)): ($!)\n"; my $newImage03 = $img->crop( left=>437, right=>654, top=>0 , +bottom=>150 ) || die "$message ($_): ($!)\n"; my $newImage04 = $img->crop( left=>0 , right=>218, top=>150, +bottom=>300 ) || die "$message ($_): ($!)\n"; my $newImage05 = $img->crop( left=>218, right=>437, top=>150, +bottom=>300 ) || die "$message ($_): ($!)\n"; my $newImage06 = $img->crop( left=>437, right=>654, top=>150, +bottom=>300 ) || die "$message ($_): ($!)\n"; # ----------- # write it out $newImage01->write(file => "$pic-01.jpg"); $newImage02->write(file => "$pic-02.jpg"); $newImage03->write(file => "$pic-03.jpg"); $newImage04->write(file => "$pic-04.jpg"); $newImage05->write(file => "$pic-05.jpg"); $newImage06->write(file => "$pic-06.jpg"); unless ($hoff) { &writeHTML($pic, $_); } } my $createCount = $count * 6; my ($secs2, $msecs2) = gettimeofday; my $stime = $secs2 - $secs; my $mtime = $msecs2 - $msecs; my $totalTime = "$stime.$mtime"; print LOG "Files processed: $count\n"; print LOG "Images created : $createCount\n"; print LOG "Processing time: $totalTime seconds\n"; close(LOG); } # ----------- # on by default sub writeHTML { my ($pic, $originalImage) = @_; my (%imageInfo, $kbytes, $sum); ($kbytes) = (stat($originalImage))[7]; my $origSize = $kbytes / 1024; $origSize =~ /(\d+)\.(\d\d)/; my $originalImageSize = "$1.$2"; my @newImages = ( "$pic-01.jpg", "$pic-02.jpg", "$pic-03.jpg", "$pic-04.jpg", "$pic-05.jpg", "$pic-06.jpg", ); foreach (@newImages) { ($kbytes) = (stat($_))[7]; my $size = $kbytes / 1024; $size =~ /(\d+)\.(\d\d)/; $imageInfo{$_} = "$1.$2"; $sum += "$1.$2"; } open(FILE, "+>$pic.html") || die "Can't create html file: ($!)\n"; print FILE "<html><head><title>$pic.jpg preview</title>\n"; print FILE "<!-- \'split\' written by David Wakeman - http://perld -->\n"; # ----------- # css style tags print FILE "<style type=\"text/css\">\n"; print FILE "\tBODY {\n"; print FILE "\t\tbackground: #FFFFFF;\n"; print FILE "\t}\n"; print FILE "\t.imageframe {\n"; #print FILE "\t\tborder: 1px solid black;\n"; print FILE "\t}\n"; print FILE "\t.titleinfo {\n"; print FILE "\t\tborder: 1px solid black;\n"; print FILE "\t\tcolor: #FF6600;\n"; print FILE "\t\tfont-family: Tahoma, Verdana, sans-serif;\n"; print FILE "\t\tfont-size: 10px;\n"; print FILE "\t\tfont-weight: normal;\n"; print FILE "\t\ttext-decoration: none;\n"; print FILE "\t}\n"; print FILE "</style>\n"; # ----------- # html meat print FILE "</head>\n"; print FILE "<body>\n"; print FILE "<center>\n"; print FILE "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\ +" width=\"200\">\n"; print FILE "<tr>\n"; print FILE " <td class=\"titleinfo\" align=\"center\"><b>File Info +rmation</b></td>\n"; print FILE "</tr>\n"; print FILE "<tr>\n"; print FILE "<td class=\"titleinfo\">\n"; print FILE "<b>Original size</b>: $originalImageSize KB<br>\n"; print FILE "<b>Combined size</b>: $sum KB\n"; print FILE "<ul>\n"; foreach (@newImages) { print FILE "<b>$_</b>: $imageInfo{$_} KB <br>\n"; } print FILE "</ul></td></tr>\n"; print FILE "</table>\n<br>\n"; # ----------- # image table print FILE "<table border=\"0\" cellpadding=\"0\" cellspacing=\"4\ +">\n"; print FILE "<tr>\n"; # ----------- # first set of images across (row 1) print FILE " <td class=\"imageframe\"><img src=\"$pic-01.jpg\" bor +der=\"0\"></td>\n"; print FILE " <td class=\"imageframe\"><img src=\"$pic-02.jpg\" bor +der=\"0\"></td>\n"; print FILE " <td class=\"imageframe\"><img src=\"$pic-03.jpg\" bor +der=\"0\"></td>\n"; print FILE "</tr><tr>\n"; # ----------- # second set of images across (row 2) print FILE " <td class=\"imageframe\"><img src=\"$pic-04.jpg\" bor +der=\"0\"></td>\n"; print FILE " <td class=\"imageframe\"><img src=\"$pic-05.jpg\" bor +der=\"0\"></td>\n"; print FILE " <td class=\"imageframe\"><img src=\"$pic-06.jpg\" bor +der=\"0\"></td>\n"; print FILE "</tr></table>\n"; print FILE "</center>\n"; print FILE "</body>\n"; print FILE "</html>\n"; close(FILE); } # ----------- # called by command-line option # or if it can't find any jpg's # in current dir. sub usage { print "\nusage: -hoff [ [filename 1] [filename 2] ]\n\n"; print " By default with no arguments will attempt to\n"; print " process every jpg file in the current directory, and will\ +n"; print " produce an html page per image 'set' so you can view outpu +t\n"; print " and see file size information.\n\n"; print "\t' foo.jpg bar.jpg foobar.jpg'\n"; print "\t\tor\n"; print "\t' -hoff foo.jpg bar.jpg foobar.jpg'\n\n"; print " The first method allows you to specify certain images and\ +n"; print " the second turns off html output and specifies only certai +n\n"; print " images to be processed. The html off option can be called +\n"; print " by itself.\n\n"; print " Please read the readme.txt associated with this program fo +r\n"; print " more info.\n"; exit; }

In reply to image splitter by djw

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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (9)
    As of 2018-06-23 18:27 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (125 votes). Check out past polls.