efl.ethumb_client.Client
Class¶efl.ethumb_client.
Client
(func, *args, **kargs)¶Bases: object
This client is the recommended way to generate thumbnails with Ethumb. All you have to do is create a client instance, wait it to be connected to server, configure thumbnail parameters and then start feed it with file_set(), exists() generate(). Basic steps are:
c.file_set(file)
if not c.exists(): c.generate(generated_cb)
When the last reference to client is released, server is
automatically disconnected. Since callback may contain references
to server itself, it is recommended explicit call to
disconnect()
function.
Parameters: |
|
---|
Expected func signature:
func(client, status, *args, **kargs)
with status being True for successful connection or False on error.
Raises: |
|
---|
aspect_get
()¶Get current aspect in use for requests.
Return type: | int |
---|
aspect_set
(a)¶Configure aspect mode to use.
If aspect is kept (ETHUMB_THUMB_KEEP_ASPECT), then image will
be rescaled so the largest dimension is not bigger than it’s
specified size (see size_get()
) and the other dimension is
resized in the same proportion. Example: size is 256x256,
image is 1000x500, resulting thumbnail is 256x128.
If aspect is ignored (ETHUMB_THUMB_IGNORE_ASPECT), then image will be distorted to match required thumbnail size. Example: size is 256x256, image is 1000x500, resulting thumbnail is 256x256.
If crop is required (ETHUMB_THUMB_CROP), then image will be
cropped so the smallest dimension is not bigger than its
specified size (see size_get()
) and the other dimension
will overflow, not being visible in the final image. How it
will overflow is speficied by crop_set()
alignment. Example: size is 256x256, image is 1000x500, crop
alignment is 0.5, 0.5, resulting thumbnail is 256x256 with 250
pixels from left and 250 pixels from right being lost, that is
just the 500x500 central pixels of image will be considered
for scaling.
Parameters: | a – aspect mode identifier, either ETHUMB_THUMB_KEEP_ASPECT (0), ETHUMB_THUMB_IGNORE_ASPECT (1) or ETHUMB_THUMB_CROP (2). |
---|
category_get
()¶Get current category sub directory to store thumbnails.
Return type: | str or None |
---|
category_set
(category)¶Category directory to store thumbnails.
Parameters: | category – category sub directory to store thumbnail. Default is either “normal” or “large” for FDO compliant thumbnails or WIDTHxHEIGHT-ASPECT[-FRAMED]-FORMAT. It can be a string or None to use auto generated names. |
---|
compress_get
()¶Get current compression level in use for requests.
Return type: | int |
---|
compress_set
(compress)¶Configure compression level used in requests.
Parameters: | compress – value from 0 to 9, default is 9. The effect depends on the format being used, JPEG will not use it. |
---|
crop_get
()¶Get current crop alignment in use for requests.
Return type: | tuple of float |
---|
crop_set
(x, y)¶Configure crop alignment in use for future requests.
Parameters: |
|
---|
directory_get
()¶Get current base directory to store thumbnails.
Return type: | str or None |
---|
directory_set
(path)¶Configure where to store thumbnails in future requests.
Note that this is the base, a category is added to this path as a sub directory.
Parameters: | path – base directory where to store thumbnails. Default is ~/.thumbnails |
---|
disconnect
()¶Explicitly request server disconnection.
After this call object becomes shallow, that is operations will be void.
document_page_set
(page)¶fdo_set
(s)¶Configure future requests to use FreeDesktop.Org preset.
This is a preset to provide freedesktop.org (fdo) standard compliant thumbnails. That is, files are stored as JPEG under ~/.thumbnails/SIZE, with size being either normal (128x128) or large (256x256).
Parameters: | s – size identifier, either ETHUMB_THUMB_NORMAL (0) or ETHUMB_THUMB_LARGE. |
---|
See also
size_set()
, format_set()
, aspect_set()
, crop_set()
,
category_set()
, directory_set()
.
file_free
()¶Zero/Reset file parameters.
This call will reset file and thumb specifications.
See also
file_set()
and thumb_set()
file_get
()¶Get current file to thumbnail.
Return type: | tuple of str |
---|
file_set
(path, key=None)¶Set file to thumbnail.
Calling this function will zero thumb_set()
specifications. This is done to avoid one using the last thumb
path for new images.
Parameters: |
|
---|
format_get
()¶Get current format in use for requests.
Return type: | int |
---|
format_set
(f)¶Configure format to use for future requests.
Parameters: | f – format identifier to use, either ETHUMB_THUMB_FDO (0), ETHUMB_THUMB_JPEG (1) or ETHUMB_THUMB_EET (2). Default is FDO. |
---|
frame_set
(file, group, swallow)¶Set frame to apply to future thumbnails.
This will create an edje object that will have image swallowed in. This can be used to simulate Polaroid or wood frames in the generated image. Remember it is bad to modify the original contents of thumbnails, but sometimes it’s useful to have it composited and avoid runtime overhead.
Parameters: |
|
---|
generate
(func, *args, **kargs)¶Ask EThumb server to generate the specified thumbnail.
Thumbnail generation is asynchronous and depend on ecore main loop running. Given function will be called back with generation status if True is returned by this call. If False is returned, given function will not be called.
Existing thumbnails will be overwritten with this call. Check
if they already exist with exists()
before calling.
Parameters: | func – function to call on generation completion, even if failed or succeeded. Signature is: func(self, id, file, key, thumb_path, thumb_key, status, *args, **kargs)
with status being True for successful generation or False on failure. |
---|---|
Returns: | request identifier. Request can be canceled calling
|
Raises: |
|
See also
cancel()
, clear()
, exists()
generate_cancel
(id)¶Cancel thumbnail request given its id.
Calling this function aborts thumbnail generation and func
given to generate()
will not be called!
Parameters: | id – identifier returned by generate() |
---|
generate_cancel_all
()¶Clear request queue, canceling all generation requests.
This will abort all existing requests, no func given to
generate()
will be called.
Same as calling cancel()
in all exising requests.
on_server_die_callback_set
(func, *args, **kargs)¶Function to call when server dies.
When server is dead there is nothing to do with this client anymore, just create a new one and start over, hope that server could be started and you could generate more thumbnails.
Parameters: | func – function to call when server dies. Signature: func(client, *args, **kargs)
|
---|---|
Raises TypeError: | |
if func is not callable or None. |
quality_get
()¶Get current quality in use for requests.
Return type: | int |
---|
quality_set
(quality)¶Configure quality to be used in thumbnails.
Parameters: | quality – value from 0 to 100, default is 80. The effect depends on the format being used, PNG will not use it. |
---|
size_get
()¶Get current size being used by requests.
Return type: | tuple of int. |
---|
size_set
(w, h)¶Configure future request to use custom size.
Parameters: |
|
---|
thumb_exists
(callback=None, *args, **kwargs)¶Checks if thumbnail already exists.
If you want to avoid regenerating thumbnails, check if they already exist with this function.
thumb_get
()¶Get current path and key of thumbnail.
Note that if no explicit thumb_set()
was called, it will
auto generate path based on existing parameters such as
directory, category and others.
Return type: | tuple of str |
---|
thumb_set
(path, key=None)¶Set thumbnail path and key.
Note that these parameters are forgotten (reset) after
file_set()
.
Parameters: |
|
---|
video_fps_set
(fps)¶video_interval_set
(interval)¶video_ntimes_set
(ntimes)¶video_start_set
(start)¶video_time_set
(time)¶