--- bin/upload Wed Aug 22 01:17:27 2001 +++ /home/www/html/caboteria/twiki-2001-09-01/bin/2/upload Sun Jan 27 22:29:30 2002 @@ -21,6 +21,7 @@ use lib ( '.' ); use lib ( '../lib' ); use TWiki; +use Image::Magick; $query = new CGI; @@ -268,6 +269,36 @@ } # ========================= +# given the fully-qualified path name, if the filename ends in a +# graphics file suffix (.gif, .jpg, .jpeg, .png) then create a +# small "thumbnail" which can be displayed in the topic page. +# 2002-01-27 toby@caboteria.org +sub createThumbnail +{ + my ( $pathFilename ) = @_; + + if( $pathFilename =~ /\.(gif|jpg|jpeg|png)$/i ) { + my( $image, $error); + + # read the image + $image = Image::Magick->new; + $error = $image->Read( "$pathFilename"); + warn "$error" if "$error"; + + # shrink it and set the quality + $error = $image->Scale(geometry=>'250x250'); + warn "$error" if "$error"; + $error = $image->Set( quality=>'75'); + warn "$error" if "$error"; + + # write it + $image->Write("$pathFilename.thumb.jpeg"); + } + + return; +} + +# ========================= sub handleError { my( $noredirect, $message, $query, $theWeb, $theTopic, @@ -404,6 +435,8 @@ if( $createLink ) { my $filePath = &TWiki::Store::getFileName( $webName, $topic, $fileName ); + # create a thumbnail image - 2002-01-27 toby@caboteria.org + createThumbnail( $filePath ); $text = addLinkToEndOfTopic( $text, $filePath, $fileName, $fileComment ); }