Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

picwoodpecker -- a Tk program to choose and modify your photos

by Discipulus (Prior)
on Nov 30, 2016 at 08:37 UTC ( #1176907=CUFP: print w/replies, xml ) Need Help??

Hello monks,

after months of sparetime works I'm proud to present you picwoodpecker my last Tk effort (now also on github).

It is application to review and copy pictures with many features.

Suggestions are welcome.Tests with exif tags from different cameras are even more welcome.

The post is splitted in 3 parts: here you have the rendered documentation, below there is the code and finally the POD that must be pasted after the __DATA__ token of the program.

               This software is dedicated to my parents, who need to see printed pictures -- 6 July 1966 

NAME

PicWoodPecker

SYNOPSIS

perl picwoodpecker.pl [-s -d -debug -pr -wr -p -x -y -nothumbs -e -quality -pngcompression -df]

OPTIONS

     -s|src|source        path
                    the path where search for jpg files to be loaded
                    Can be modified in the Tk interface

-d|dest|destination path path used to save files Can be modified in the Tk interface

-debug print more information on the screen Can be modified in the Tk interface

-pr|phratio floating point the ratio used to display the current photo Can be modified in the Tk interface

-wr|winratio floating point the ratio to size the window where the photo is displayed Can be modified in the Tk interface

-p|preload integer how many photos load in memory after and before the current one. Can increase drawing speed time

-x|gridx integer how many columns in the thumbnail grid

-y|gridy integer how many rows in the thumbnail grid

-nothumbs does not load thumbnails at all

-e|extension jpg|gif|png|gd|gd2 the exstension of saved files Can be modified in the Tk interface

-quality|jpegquality 0-100 the quality of the file used by GD when saving the current photo in jpeg format An empty value let GD to choose a good default Can be modified in the Tk interface

-pngcompression 0-9 the compression factor used by GD when saving the current photo in png format -dateformat|df string the format used for dates. It defaults to %Y_%m_%d_%H_%M_%S in such way resulting pics can be ordered correctly. See C<strftime> in L<POSIX> to more hints about formatting.

DESCRIPTION

The program is aimed to let you to easely choose among photos and save one (or more) copy in the preferred format (jpg as default; gif png gd and gd2 are also available). The name of the copy is crafted using the timestamp when the photo was taken.

Basically the program will load all jpg files found globbing the path given with command line parameter -source or entered in the graphical interface, and foreach file will examine some exif tags to get sizes, timestamps and the thumbnail (if not present showing a black empty one).

Orientation of the image is handled automatically for thumbnails and main photo.

Advanced options are available to manipulate how many photos are copied, in which format and let you to postprocess via exiftool each created image.

The program uses GD for image manipulation and Image::ExifTool to load infos from photos and in the postprocess of them.

THE GRAPHICAL INTERFACE

A main control window and a display one are created. Optionally a third window is created to access the advanced copy options. The display window tends to take the focus being the program focused on displaying photos.

control window

The control window contains:

  • all controls to manipulate the photo list (&#39;browse&#39; &#39;new list&#39; &#39;view list&#39; &#39;add to list&#39; and &#39;clear list&#39;) Note the that the &#39;browse&#39; does not fill the list; you need to use &#39;new list&#39; or &#39;add to list&#39; after using it.
  • an entry to choose the destination folder (that will be checked for existence)
  • the photo ratio and the window ratio controls and the debug switch
  • an informative text about the current displayed photo or about the grid of thumbnails
  • the editable name of the current photo (and an eventual suffix) used to save it
  • an information text about the status of the main program (with only relevant information about copying and loading operations as eventual errors)
  • the save button and the advanced options one.
  • controls to navigate the photo list

display window

The display window will starts showing a grid of thumbnails. The first one is selected. You can navigate the grid using right arrow and left arrow of the keyboard to move the current selection on or back.

up arrow and down arrow let you load previous or next grids of thumbanails.

Enter key will open the currently selected thumbanil in a bigger resolution ( determinted by photo ratio parameter) photo filling the whole window.

When just one photo is displayed right arrow and left arrow of the keyboard can be used to show next and previous photo while up arrow and down arrow bring you back to the thumbnail view.

In both control and display window space bar can be used to save the current photo and p key can be used to toggle autoplay. If autoplay is active the time between photos can be set in the control window. Please note that specifying a short amount of time (shorter than the time needed to load photos data) can produce weird showing behaviours.

advanced copy options

This menu lets you to have a granular control about how original photo will be copied.

The allow overwrite if checked silently overwrite a photo wich has the same name of what is composed for the current one.

bypass original file elaboration (simple copy) make a copy of the original file using the new name but without processing it with GD

output file type lets you to choose among different file fomrmats (jpeg, gif, png, gd and gd2) and to set the quality (0-100) for jpeg ones. For png files the compression factor (0-9) can be specified only via the command line parameter -pngcompression

enable multiple copies is trickier. If enabled lets you to choose to copy the file many times, each one with a different resolution. In the multi copies pattern you can specify different resolutions in the format widthxheigth as in 800x600 or 1024x768 and for each format a copy will be created.

enable post processing can be used to postprocess every image with exiftool program that ships with Image::ExifTool module. You can use alternative program to postprocess your image inserting the full path in the program field. Arguments to such program can be also specified where $ can be used to refer to the full path of the original image. In the exiftool command line you can also specify @ to refer to the current file. So you can postprocess every copy using the following arguments:

-overwrite_original -all= -tagsFromFile $ -ImageSize -ImageWidth -ImageHeight -ThumbnailImage -Orientation -DateTimeOriginal

This exiftool command will be issued for every copy made, overwriting each exif tags in the copy, removing them all but taking some tag frome the original file and applying them to the copy. See the exiftool page for a lot of options this wonderful program lets you to use.

LIMITATIONS

The program was tested against few different camera formats; i dont know if exif tags extracted are widely valid.

The autoplay feature does not plays well with little time intervals: infact when the interval is smaller than the overall time taken to load the the photo and to redesign the display i'll notice photos and information skipped and the timer going on. I tried fixing this using waitVisibility Tk method, with no luck.

COPYRIGHT

This software and icons are copyright of Discipulus as found on www.perlmonks.org You may redistribute or modify it under the same term of Perl itself.

L*

Replies are listed 'Best First'.
Re: PicWoodPecker -- a Tk program to choose and modify your photos
by kcott (Chancellor) on Nov 30, 2016 at 21:56 UTC

    G'day Discipulus,

    I put the code and POD in a file, made a small change to the shebang line, and ran it without any options:

    $ picwoodpecker.pl Empty list searching [./*.jpg]! bad event type or keysym "?" at /long/perlbrew/path/Tk/Derived.pm line + 469.

    So my first suggestion was to allow the -source path to be selected after the GUI starts if none was specified on the command line (given the POD says this can be changed from the GUI).

    Anyway, I tried again a couple of times using different paths with the -s option. Both gave an "ERROR creating a thumbnail ..." message as well as the "bad event type ..." message I noted above. I was able to independently open and view both images: they looked fine. I tried again with the -debug option you've supplied. Here's the entire output:

    $ picwoodpecker.pl -s ~/local/doc/misc -debug build_list received [/Users/ken/local/doc/misc] DIR found: [/Users/ken/local/doc/misc] will be converted to [/Users/ke +n/local/doc/misc/*.jpg] Please wait while processing 1 files.... adding /Users/ken/local/doc/misc/Mandel_zoom_00_mandelbrot_set.jpg ERROR creating a thumbnail for file [/Users/ken/local/doc/misc/Mandel_ +zoom_00_mandelbrot_set.jpg].I will use an empty one. bad event type or keysym "?" at /Users/ken/perl5/perlbrew/perls/perl-5 +.24.0t/lib/site_perl/5.24.0/darwin-thread-multi-2level/Tk/Derived.pm +line 469.

    I also tried the widget demo. Both applications in the "Photos and Images" section worked without any issues.

    I gave up testing at this point; however, I don't mind testing some more if you want to suggest other options, provide a URL to some test image(s), or make code changes.

    In general, this does sound like a good idea. One further suggestion would be to allow other formats for the source images: adding Tk::PNG would be more useful for me personally (as an example, I searched my entire '~/local/doc/' tree for '*.jpg' files to test your GUI but only found 2; the same search for '*.png' files found 62).

    — Ken

      Hello kcott,

      first of all thanks for the feedback! Having someone else spending his time looking at my code is something make me happy.

      There are three issues:

      1-the population of pic list

      2-the bad event type or keysym "?" at..

      3-the ERROR creating a thumbnail for file one

      About the second i need to investigate a bit, because i do not understand it. The application has a binding to the ? key to popup a new mainwindow with the rendered POD. It also has some special unbinding for key ? for all Entry widgets.

      This issue possibly resolve itself changing in the code all <KeyRelease-?> declaration into <KeyRelease-question> ones.

      About the first issue you pose it is related to the list population: maybe i've badly explained in the documentation.

      By default the app search the current directory for jpeg files: ie it globs ./*.jpg and build the list. If no image are found it complains about in the console.

      perl c:\SCRIPTS\resized\picwoodpecker-v10.10.pl -s c:/scripts/resized/ +user -debug build_list received [c:/scripts/resized/user] DIR found: [c:/scripts/resized/user] will be converted to [c:/scripts/ +resized/user/*.jpg] No file to process

      If so you can select a new directory to search using the GUI: the button browse to choose the dir and new list one to populate it. Or you could simply write the dir or the glob expression into the source entry.

      In the docs i put the phrase: Note the that the browse does not fill the list; you need to use new list or add to list after using it.

      The app is already able to process png files: you must tell it using the source/glob expression:

      perl c:\SCRIPTS\resized\picwoodpecker-v10.10.pl -s c:/scripts/*.png -d +ebug build_list received [c:/scripts/*.png] Please wait while processing 6 files.... adding c:/scripts/colorRamp.png adding c:/scripts/Mandelbrot_Love_by_sya.png adding c:/scripts/out.png adding c:/scripts/test.png adding c:/scripts/testHEX.png adding c:/scripts/testHEX2.png

      Finally the thumbnail errors: the application search for and embedded thumbnail that usually is present in jpg photos but not in other files formats. If the embedded thumb is not present the program emit the error (maybe is better a warning?) and creates an empty one ie a black one using GD.

      Perhaps the best behaviour is search for an embedded thumb and make it up a new one if not found. I'll put the program on github and I'll try to add suche feature.

      thanks again

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Hello kcott,

      I put the program on github: can you be so kind to try if the keysim error disappears using this release?

      Thanks for your time.



      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        The short answer is "no". I ran exactly the same commands as shown previously and got exactly the same output.

        My current perl:

        $ perl -v | head -2 | tail -1 This is perl 5, version 24, subversion 0 (v5.24.0) built for darwin-th +read-multi-2level

        I have lots of Perl versions installed. What are you using?

        I already had the latest Tk. I initially needed to install GD and Image::ExifTool. Here's the versions of all of those:

        Tk 804.033 GD 2.56 Image::ExifTool 10.36

        The shebang line change I made was minimal:

        $ head -1 picwoodpecker.pl #!/usr/bin/env perl

        I don't really have the time to look closely at your 1,828 lines of code. I did quickly scroll through it. One thing I did notice was multiple function calls like:

        &func

        While that may be intentional, are you aware of the side effects (described in perlsub). The more usual form is:

        func()

        I didn't investigate whether those side effects had any bearing on the current issues.

        — Ken

Re: PicWoodPecker -- a Tk program to choose and modify your photos -- the code
by Discipulus (Prior) on Nov 30, 2016 at 08:41 UTC
    Here the code because the OP was too big...
Re: PicWoodPecker -- a Tk program to choose and modify your photos -- the POD
by Discipulus (Prior) on Nov 30, 2016 at 08:45 UTC
    After the __DATA__ you must paste the POD documentation:

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://1176907]
Approved by Athanasius
Front-paged by kcott
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2017-06-28 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (628 votes). Check out past polls.