Bases: object
Client for Ethumbd server.
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:
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: |
|
---|
Get current aspect in use for requests.
Return type: | int |
---|
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). |
---|
Get current category sub directory to store thumbnails.
Return type: | str or None |
---|
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. |
---|
Get current compression level in use for requests.
Return type: | int |
---|
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. |
---|
Get current crop alignment in use for requests.
Return type: | tuple of float |
---|
Configure crop alignment in use for future requests.
Parameters: |
|
---|
Get current base directory to store thumbnails.
Return type: | str or None |
---|
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 |
---|
Explicitly request server disconnection.
After this call object becomes shallow, that is operations will be void.
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().
Zero/Reset file parameters.
This call will reset file and thumb specifications.
See also
file_set() and thumb_set()
Get current file to thumbnail.
Return type: | tuple of str |
---|
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: |
|
---|
Get current format in use for requests.
Return type: | int |
---|
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. |
---|
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: |
|
---|
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 cancel() with given id. If an identifier is returned (>= 0), then func is guaranteed to be called unless it is explicitly canceled. |
Raises: |
|
See also
cancel(), clear(), exists()
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() |
---|
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.
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. |
Get current quality in use for requests.
Return type: | int |
---|
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. |
---|
Get current size being used by requests.
Return type: | tuple of int. |
---|
Configure future request to use custom size.
Parameters: |
|
---|
Checks if thumbnail already exists.
If you want to avoid regenerating thumbnails, check if they already exist with this function.
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 |
---|
Set thumbnail path and key.
Note that these parameters are forgotten (reset) after file_set().
Parameters: |
|
---|