Simple Random Image Viewer in Python




Usually, I use my flickrRandomImage python script to fetch some random images from my flickr account to amuse myself. However, it heavily depends on the internet access speed. When the network traffic is jammed, it takes a long time to generate 10 thumbnails for each run. Therefore, I decided to go for another way: create a simple image viewer which can randomly pick photos from a designated folder on local hard disk.

Once the decision is made, it won't take too much time to find a starting solution. By choosing python as the development programming language, I can easily find the samples I need on the internet. The first step is to find a workable image viewer written in python. This is not a difficult task because python's library set is very rich; image viewer is something people tend to write as a sample app.

Well, this's what I found:creating-a-simple-photo-viewer-with-wxpython/.
This sample basically provides most of the features I need:
1) pop up a directory dialog to choose a folder
2) to view images in forward/backward direction
3) to toggle Slide View

What's left is:
1) load image files recursively in a folder
2) show image randomly instead of in predefined sequence
3) rotate the image according to the exif orientation information
4) launch image file format associated application to do other actions
5) track the viewed sequence in order to view backward

1) this is easy part. Check out os.path.walk and search on the internet.
2) use "from random import choice"
3) import exif.py and check the value of "Image Orientation".
    use wxImage.Rotation90 to rotate image accordingly
4) use os.startfile()
5) use a list to keep track of viewed photos


No comments:

Post a Comment