- Generate thumbnail images for documents and media files.
- Interface to Flash applets via Local Connection, allowing text messages of up to 256 bytes to be sent to and from Flash.
The thumbnails are generated using IExtractImage, which is part of the Windows XP API. Windows XP uses IExtractImage to produce the thumbnail images that appear in the default XP file browser. (Earlier versions of Windows lack this feature.) The link to Flash uses Local Connection, which is implemented using some public domain C code written by Philippe Elsass. The two parts of the program are turned into Python methods using SWIG.
Build instructionsUnfortunately, due to software incompatibilities, you can only use a Python extension that was compiled with the same version of Visual Studio as Python itself. Therefore, you should download the Python source and compile it yourself before you compile this extension. Then the two programs will match. For this reason, I am not distributing the binary version of this program.
Compile Python 2.5 (or later) using Visual Studio. Then unzip the thumbnail software (below). Edit the "build_extension.bat" script, and set the correct location of the newly compiled python.exe. Then run "build_extension.bat" in a Command Prompt window.
Usage exampleThe component parts of the module (once compiled) are:
- api.py - Python container. This is what you should import.
- _features.pyd - Code written in C. (No need to import this directly.)
- features.py - C/Python wrapper. (No need to import this directly.)
- demo.py - Demo program written in Python
- client.fla - Local connection demo
- client.swf - Local connection demo
- demo.png - A thumbnail is made of this image
- create "thumbnail.jpg" from "demo.png"
- wait for a LocalConnection (forever).
APIThe following functions are in the api.py module:
- Thumbnail(source_file, dest_file, image_size)
A function for making thumbnails. Returns True on success. False is returned if a thumbnail couldn't be made for that particular type of file.
This function might also raise an exception. IOError will be raised if you try to Thumbnail a file that does not exist, or tell Thumbnail to save somewhere that can't be written. SeriousProblem is raised if thumbnails can't be made at all. (This happens on Windows 2000.)
Add a message to the outgoing queue. The message must be a string. The message is never sent until LocalConn_Poll is called. You can have lots of messages in the outgoing queue at once. All of them are sent in order by calls to LocalConn_Poll.
Returns the next message in the incoming queue (a string), or None if no messages are waiting. You must call LocalConn_Poll to obtain new messages because Receive_Message only checks the queue.
Polls the local connection interface for new messages, and sends messages in the outgoing queue. Your program should call this function at regular intervals. It may raise the SeriousProblem exception if an error occurs.
A custom exception used by Thumbnail and LocalConn_Poll.