RE: Perl and Images
steve silvers <> wrote: : Is there really no easier way to do this? All I need is to point it : to a directory, this directory will have just .html files in it. Then : just render a image or images to the browser of what each .html file : looks like. That is not an easy task. An html file is a text file. It does not have any information in it to render it as an image. All the rendering is done by a separate program. To get an image of the page requires a rendering tool and an image capture tool. To reduce the size of an image to a thumbnail often requires a very good graphics library. None of those three is a trivial solution. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Perl and Images
Is there really no easier way to do this? All I need is to point it to a directory, this directory will have just .html files in it. Then just render a image or images to the browser of what each .html file looks like. Thanks in advance Steve From: "Chris Snyder" <[EMAIL PROTECTED]> To: "'steve silvers'" <[EMAIL PROTECTED]>, Subject: RE: Perl and Images Date: Tue, 17 May 2005 16:17:13 -0500 -- snip 8< -- From: steve silvers [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 17, 2005 12:44 PM To: perl-win32-users@listserv.ActiveState.com Subject: Perl and Images Quick question. Is there a way that I can go into a directory with a static html file in it and create a thumbnail image of the html file? Any suggestions or examples greatly appreciated. Steve -- snip 8< -- There are a lot of scripts out there that do that sort of thing. I wrote one a few years ago that I used on my web site. It created a thumbs directory and made the thumbnails, and resized the images to a maximum size (all configurable). It uses Image::Magick which I recall may have been somewhat difficult to install. Going from memory, I believe I had to just install the app and put the perl module files where they belong, bypassing the perl installation / testing routines. Anyway, It's not pretty, but it worked fine last time I used it. The script is for CGI, but can be converted to command line as all it does it produce a basic log file. Here is the script (the module I wrote ImageIndex.pm is at the bottom): begin script --#!/usr/bin/perl -w use strict; use CGI; use CGI::Carp; use Data::Dumper; require ImageIndex; require Image::Magick; print CGI::header(); my $dirLoc = CGI::param("dirLoc") || '../grace/Photos1'; my $imageIndex = ImageIndex->new( "maxWidth" => 800, "maxHeight" => 600, "dirLoc" => CGI::param("dirLoc") || '../grace/Photos1', "HTMLDirLoc" => CGI::param("HTMLdirLoc") || '/grace/Photos1', "thumbLoc" => './thumbs', "xmlFileName"=> 'pictures.xml', "overwriteXML" => 0, "thumbMaxWidth" => 100, "thumbMaxHeight" => 100 ); my @messages; print < Image Magick Resizer EOHTML eval { print "opening directory\n"; if ($dirLoc && -d $dirLoc) { #dirloc was passed as a param and the directory exists print "is a directory\n"; print "height = ".$imageIndex->maxHeight.", width = ".$imageIndex->maxWidth." from imageIndex.\n"; opendir(DIRFH, $dirLoc) or die "CANTOPENDIR: $@"; my @fileList = grep {/[\.jpg|\.jpeg]$/i && (! -d $_)} readdir DIRFH; die "NOFILELIST" if ([EMAIL PROTECTED]); print "Number of files = ".scalar(@fileList)."\n"; my @pictures; for (@fileList) { my $fileName = $_; my $fullName = ImageIndex::pathFile($dirLoc, $fileName); my $message = "fullName = '$fullName'..."; print "Dealing with fullName $fullName\n"; if (-f $fullName) { my $picture = $imageIndex->newPicture(dirLoc => $dirLoc, fileName => $fileName); print "got picture object\n"; $message .= $picture->resizeImage."\n"; my $thumb = $picture->mkThumb; print "resized thumb\n"; } else { print "file $fullName does not exist\n"; $message .= "file $fullName does not exist"; } push @messages, $message; } closedir DIRFH; } else { print "no dirLoc: $dirLoc" unless $dirLoc; } }; print "done\n"; print "error: $@" if $@; print "$_\n" for @messages; print ""; end script -- -- Begin ImageIndex.pm --- #!/usr/bin/perl -w use strict; use Data::Dumper; use Image::Magick; package ImageIndex; sub BEGIN { %ImageIndex::defaultArgs = ( "maxWidth" => 800, "maxHeight" => 600, "dirLoc" => '', "thumbLoc" => './thumbs', "xmlFileName"
RE: Perl and Images
-- snip 8< -- From: steve silvers [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 17, 2005 12:44 PM To: perl-win32-users@listserv.ActiveState.com Subject: Perl and Images Quick question. Is there a way that I can go into a directory with a static html file in it and create a thumbnail image of the html file? Any suggestions or examples greatly appreciated. Steve -- snip 8< -- There are a lot of scripts out there that do that sort of thing. I wrote one a few years ago that I used on my web site. It created a thumbs directory and made the thumbnails, and resized the images to a maximum size (all configurable). It uses Image::Magick which I recall may have been somewhat difficult to install. Going from memory, I believe I had to just install the app and put the perl module files where they belong, bypassing the perl installation / testing routines. Anyway, It's not pretty, but it worked fine last time I used it. The script is for CGI, but can be converted to command line as all it does it produce a basic log file. Here is the script (the module I wrote ImageIndex.pm is at the bottom): begin script --#!/usr/bin/perl -w use strict; use CGI; use CGI::Carp; use Data::Dumper; require ImageIndex; require Image::Magick; print CGI::header(); my $dirLoc = CGI::param("dirLoc") || '../grace/Photos1'; my $imageIndex = ImageIndex->new( "maxWidth" => 800, "maxHeight" => 600, "dirLoc" => CGI::param("dirLoc") || '../grace/Photos1', "HTMLDirLoc" => CGI::param("HTMLdirLoc") || '/grace/Photos1', "thumbLoc" => './thumbs', "xmlFileName"=> 'pictures.xml', "overwriteXML" => 0, "thumbMaxWidth" => 100, "thumbMaxHeight" => 100 ); my @messages; print < Image Magick Resizer EOHTML eval { print "opening directory\n"; if ($dirLoc && -d $dirLoc) { #dirloc was passed as a param and the directory exists print "is a directory\n"; print "height = ".$imageIndex->maxHeight.", width = ".$imageIndex->maxWidth." from imageIndex.\n"; opendir(DIRFH, $dirLoc) or die "CANTOPENDIR: $@"; my @fileList = grep {/[\.jpg|\.jpeg]$/i && (! -d $_)} readdir DIRFH; die "NOFILELIST" if ([EMAIL PROTECTED]); print "Number of files = ".scalar(@fileList)."\n"; my @pictures; for (@fileList) { my $fileName = $_; my $fullName = ImageIndex::pathFile($dirLoc, $fileName); my $message = "fullName = '$fullName'..."; print "Dealing with fullName $fullName\n"; if (-f $fullName) { my $picture = $imageIndex->newPicture(dirLoc => $dirLoc, fileName => $fileName); print "got picture object\n"; $message .= $picture->resizeImage."\n"; my $thumb = $picture->mkThumb; print "resized thumb\n"; } else { print "file $fullName does not exist\n"; $message .= "file $fullName does not exist"; } push @messages, $message; } closedir DIRFH; } else { print "no dirLoc: $dirLoc" unless $dirLoc; } }; print "done\n"; print "error: $@" if $@; print "$_\n" for @messages; print ""; end script -- -- Begin ImageIndex.pm --- #!/usr/bin/perl -w use strict; use Data::Dumper; use Image::Magick; package ImageIndex; sub BEGIN { %ImageIndex::defaultArgs = ( "maxWidth" => 800, "maxHeight" => 600, "dirLoc" => '', "thumbLoc" => './thumbs', "xmlFileName"=> 'pictures.xml', "overwriteXML" => 0, "thumbMaxWidth" => 100, "thumbMaxHeight" => 100, "makeDirs" => 1 ); } sub new { my ($class, %args) = @_; my %newArgs; for my $keyName (keys %ImageIndex::defaultArgs) { if (exists $args{$keyName}) { $newArgs{$keyName} = $args{$keyName}; } else { $newArgs{$keyName} = $ImageIndex::defaultArgs{$keyName}; } my $subName = $class.'::'.$keyName; eval { if (!defined(*$subName)) { no strict 'refs'; *$subName = sub {my $self = shift; @_?$self->{$keyName} = shift():$self->{$keyName};}; } } } return bless(\%newArgs, $class); } sub newPictu
RE: Perl and Images
This is a little bit of an off-topic solution but I was faced with a similar task where I had to do screen dumps of clients in our machine farm as problems arose. I didn't find a hands-off solution with Perl (not to say it doesn't exist; it just wasn't right in my face). I was, however, able to automate the process VERY easily with python using PIL (Python Image Library) and the ImageGrab module. If you use this (or a perl equivalent) and you want to go straight from HTML to a JPEG, you should be able to launch a process against the HTML file which should fire off you browser (assuming file associations are set correctly on the machine) and then do the screen dump. Again, you'll probably get more elegant solutions but this is quick and dirty (especially if you already have python on your machine and don't mind making an external system call). The python script is literally as simple as: import Image import ImageGrab import traceback # simple python script that does a screen dump try: jpegfile = "screenshot.jpg" ImageGrab.grab().save(jpegfile) print "Done!" except Exception,e: traceback.print_exc() ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Perl and Images
And with that said, use the Win32::GuiTest module to send the keystrokes to the windows machine for otherwise unprogrammable tasks... Search for "SendKeys" on the activestate archive list for more info if you need it. It's pretty much like typing keystrokes. :) Steven -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gardner, Sam Sent: Tuesday, May 17, 2005 11:54 AM To: 'steve silvers'; perl-win32-users@listserv.ActiveState.com Subject: RE: Perl and Images Yes: 1) Open directory 2) Double-click file 3) Alt-PrintScreen 4) Open Paint 5) Ctrl-V 6) Save Okay, maybe you'll have to play around with this to get the thumbnail, but you get the idea. . . Sam Gardner GTO Application Development Keefe, Bruyette & Woods, Inc. 212-887-6753 -Original Message- From: steve silvers [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 17, 2005 1:44 PM To: perl-win32-users@listserv.ActiveState.com Subject: Perl and Images Quick question. Is there a way that I can go into a directory with a static html file in it and create a thumbnail image of the html file? Any suggestions or examples greatly appreciated. Steve ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Perl and Images
Title: RE: Perl and Images Yes: 1) Open directory 2) Double-click file 3) Alt-PrintScreen 4) Open Paint 5) Ctrl-V 6) Save Okay, maybe you'll have to play around with this to get the thumbnail, but you get the idea. . . Sam Gardner GTO Application Development Keefe, Bruyette & Woods, Inc. 212-887-6753 -Original Message- From: steve silvers [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 17, 2005 1:44 PM To: perl-win32-users@listserv.ActiveState.com Subject: Perl and Images Quick question. Is there a way that I can go into a directory with a static html file in it and create a thumbnail image of the html file? Any suggestions or examples greatly appreciated. Steve ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs