#!/usr/bin/perl # New imgconvert! Now in Perl, and based on Imlib2 # Get Imlib2::Perl @ http://freshmeat.net/projects/imlib2perl/ # This is a hacked up compatibility version at the request of Trae McCombs # (http://occy.net/). The changes makes it so I don't have to convert my # image viewing stuff either. (Garrett) # Copyright (c) 1999 - 2002 Garrett LeSage (http://linuxart.com/) # This script is freely distributable, modifyable, yadda-yadda under the # artistic license. http://www.perl.com/language/misc/Artistic.html use File::Basename; use File::Copy; use Imlib2; # Widths requested; first is thumb size, second is default click size. # These are later sorted for the resolution list display @imgsizes = ( 100, 640, 800, 1024 ); # Default extension $ext = ".jpg"; # Wrap at this number $numwrap = "4"; # Site Title $stitle = "LinuxArt.com"; # Default page title prefix $ptitle = "My pictures: "; # Default page title $title = ""; # Loop per image, and scale each to the respective imgsizes $path = "."; opendir DIR, $path; @dlist = readdir DIR; @flist = grep { !-d "$path/$_" } @dlist; #no directories @blist = grep { !-T "$path/$_" } @flist; #no text files, only binaries closedir DIR; # Extract the files that mach the extension only @imglist = grep { ".*$ext\$" } @blist; # Test for scaled subdir, and create if not found. #if ( !-d "$path/scaled/" ) { #print "Scaled directory not found -- creating dir...\n"; #mkdir("$path/scaled/"); #} # Change title to dir name if title is not set if ( $title eq "" ) { $title = ( split "/", `pwd` )[-1]; } foreach $imagename (@imglist) { # Load the image and then set the working context to the loaded image $image = Imlib2::load_image($imagename); Imlib2::set_context($image); # Grab the image's width and height info $width = Imlib2::get_width(); $height = Imlib2::get_height(); $basename = basename( $imagename, $ext ); push ( @bnamelist, $basename ); # Debugging info print "\n$basename: ${width}x${height} \n"; foreach $size (@imgsizes) { if ($size == $imgsizes[0]) { $revisedsize="thumb"; } else { $revisedsize=$size; } if ( !-e "$path/$revisedsize/" ) { mkdir("$path/$revisedsize/"); } if ( !-e "$path/$revisedsize/$basename.$revisedsize$ext" ) { # Ensure that we're basing the stuff from the original image Imlib2::set_context($image); # Set the width to that which is requested, and the height # is a respective ratio $width2 = $size; $height2 = $height / $width * $width2; # Debugging info print "${width2}x${height2} "; # The actual rescaling Imlib2 call $foo = Imlib2::create_cropped_scaled_image( 0, 0, $width, $height, $width2, $height2 ); # Change context to the result, and save it. Imlib2::set_context($foo); Imlib2::save_image("$path/$revisedsize/$basename.$revisedsize$ext"); Imlib2::free_image(); } else { print "$size -- "; print "Exists! Skipped.\n"; } } if ( !-e "$path/$width/" ) { mkdir("$path/$width/"); } symlink("../$imagename","$path/$width/$basename.$width$ext"); Imlib2::set_context($image); Imlib2::free_image(); push ( @HTML, "" ); } foreach $htmlsnip ( reverse(@HTML) ) { $curpic = $bnamelist[ $#imglist - $i ]; $i++; if ( $i % $numwrap == 1 ) { $linestart = '
"; # Page footer $pfoot = ""; open( OUTFILE, ">index.html" ); print OUTFILE $phead . $page . $pfoot; close(OUTFILE); print "\nDone!\n\n";