Ethumb - Thumbnail generation library
Table of Contents
Features
- create thumbnails with a predefined frame (possibly an edje frame);
- have an option to create fdo-like thumbnails;
- have a client/server utility;
- TODO: make thumbnails from edje backgrounds, icons and themes;
API
It's possible to set the following properties of thumbnails:
- size;
- format (jpeg, png, eet...);
- aspect:
- have crop?
- crop alignment?
- video:
- video_time
- document:
- page
- frame: edje file, group and swallow part to use when generating thumbnails
- directory: directory where to save thumbnails
- category: to be used as DIRECTORY/CATEGORY/md5.format
Path generation should provide the following:
- If no path to save the thumbnail is specified, the following is used:
- if category, return ~/.thumbnail/CATEGORY/md5.format
- else if size (128x128 or 256x256), format (png), aspect (keep aspect, no crop) and no frame matches, return ~/.thumbnail/{normal,large}/md5.png
- else return WxH-FORMAT-[framed-]ASPECT
Client server provides the following:
- multiple client support
- per-client configuration, avoid exchanging parameters over and over again
- per-client queue, when client disconnect (ie: dies), remove whole queue
- all clients have same priority, so queue is mixed for processing
- cancel thumb generation request
- communication over (for now) dbus and (future) ecore-ipc and unix sockets
- interface of client library is independent of the communication method selected
Examples of use
The Ethumb library can be used directly inside your code or server-client way.
- The first one can be used inside any application, but it may block it depending on what kind of thumbnail your application has requested (e.g. an image or pdf); it also may use the ecore main loop to generate the thumbnail (e.g. thumbnail from a video);
- The second one won't block your application, but requires a dbus daemon running and may start another process (actually, two new process) to attend your application requests.
Example of how to use the Ethumb library inside your code: source:trunk/ethumb/src/bin/ethumb.c
Basically your application needs to do the following:
// Get a new ethumb object e = ethumb_new(); // Setup any properties that aren't default ethumb_thumb_size_set(e, 192, 192); ethumb_thumb_category_set(e, "custom_category"); // Define a callback that will be called when the thumbnail is ready (or failed) void generated_cb(void *data, Ethumb *e, Eina_Bool success) { if (success) ethumb_thumb_path_get(e, &path, &key); // here you get the filename of the generated thumbnail // request other thumbnail if necessary else // do some error handling }
The thumbnail request may come from any part of your code, and just needs the following:
// set the origin file that we will generate the thumbnail ethumb_file_set(e, "filename.jpg", NULL); if (!ethumb_exists(e) // start thumb generation ethumb_generate(e, generated_cb, NULL); // return to the main_loop
Using the client-server API is much like using the library itself. This example ilustrates it well: source:trunk/ethumb/src/tests/ethumb_dbus.c
About the server
The server is basically a process that handles every thumbnail request via dbus from various clients, putting each request on the respective queue (one queue per client), and process one request at a time. It also spawns a child process on startup that actually generates the thumbnails, and has an ethumb per client. Communication between the server and this child process is done via pipe.
When a client connects to the server and asks for thumbnails, the following is done by the server:
- ethumbd creates a new object path and an entry on this table for this client requests;
- each thumbnail request is put in the queue for this client;
- a ethumb setup is put in the same queue, so that if you ask for a thumbnail, then change the config, and ask for another thumbnail, only the second thumbnail will be generated with the new config;
- an idler on the server gets a thumbnail request from the next queue and sends it to the spawned child process;
- the child process has an ethumb for each client, and process that thumbnail request on the right ethumb;
- on the generated callback, a message is sent to the server (via pipe);
- the server sends a dbus signal to the client telling that the thumbnail request is ready (or failed);
Here is a diagram representing the status of the server with several clients connected, with requests being processed:
References
- existing epsilon code in Enlightenment SVN: http://trac.enlightenment.org/e/browser/trunk/epsilon
- http://trac.enlightenment.org/e/wiki/EFLRecipes/Thumbnailer
Attachments
-
Anjuta_attach.2.jpg
(45.6 KB) - added by buergi
3 weeks ago.
Image by Audifahrer from old wiki
-
Anjuta_main.2.jpg
(125.8 KB) - added by buergi
3 weeks ago.
Image by Audifahrer from old wiki
