Fs Image Thumbnail
This module extends the fs_image addon to support the creation and the storage of thumbnails for images. This module is a technical module and is not meant to be installed by end-users. It only provides a mixin to be used by other modules and a model to store the thumbnails.
Table of contents
Use Cases / Context
In some specific cases you may need to generate and store thumbnails of images in Odoo. This is the case for example when you want to provide image in specific sizes for a website or a mobile application.
This module provides a generic way to generate thumbnails of images and store them in a specific filesystem storage. Indeed, you could need to store the thumbnails in a different storage than the original image (eg: store the thumbnails in a CDN) to make sure the thumbnails are served quickly when requested by an external application and to avoid to expose the original image storage.
This module uses the fs_image module to store the thumbnails in a filesystem storage.
The shopinvader_product_image addon uses this module to generate and store the thumbnails of the images of the products and categories to be accessible by the website.
Usage
This addon provides a convenient way to get and create if not exists image thumbnails. All the logic is implemented by the abstract model fs.image.thumbnail.mixin. The main method is get_or_create_thumbnails which accepts a FSImageValue instance, a list of thumbnail sizes and a base name.
When the method is called, it will check if the thumbnail exists for the given sizes and base name. If not, it will create it.
The fs.thumbnail model provided by this addon is a concrete implementation of the abstract model fs.image.thumbnail.mixin. The motivation to implement all the logic in an abstract model is to allow developers to create their own thumbnail models. This could be useful if you want to store the thumbnails in a different storage since you can specify the storage to use by model on the fs.storage form view.
Creating / retrieving thumbnails is as simple as:
from odoo.addons.fs_image.fields import FSImageValue
# create an attachment with a image file
attachment = self.env['ir.attachment'].create({
'name': 'test',
'datas': base64.b64encode(open('test.png', 'rb').read()),
'datas_fname': 'test.png',
})
# create a FSImageValue instance for the attachment
image_value = FSImageValue(attachment)
# get or create the thumbnails
thumbnails = self.env['fs.thumbnail'].get_or_create_thumbnails(image_value, sizes=[(800,600), (400, 200)], base_name='my base name')
If you’ve a model with a FSImage field, the call to get_or_create_thumbnails is even simpler:
from odoo import models
from odoo.addons.fs_image.fields import FSImage
class MyModel(models.Model):
_name = 'my.model'
image = FSImage('Image')
my_record = cls.env['my.model'].create({
'image': open('test.png', 'rb'),
})
# get or create the thumbnails
thumbnails = record.image.get_or_create_thumbnails(my_record.image,
sizes=[(800,600), (400, 200)], base_name='my base name')
Changelog
16.0.1.0.1 (2023-10-04)
Bugfixes
The call to the method get_or_create_thumbnails on the fs.image.thumbnail.mixin class returns now an ordered dictionary where the key is the original image and the value is a recordset of thumbnail images. The order of the dict is the order of the images passed to the method. This ensures that when you process the result of the method you can be sure that the order of the images is the same as the order of the images passed to the method. (#282)
Bug Tracker
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.
Do not contact contributors directly about support or help with technical issues.
Credits
Contributors
Laurent Mignon <laurent.mignon@acsone.eu> (https://acsone.eu)
Do Anh Duy <duyda@trobz.com> (https://trobz.com)
Other credits
The development of this module has been financially supported by:
Maintainers
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
Current maintainer:
This module is part of the OCA/storage project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Metadata
Release files for odoo-addon-fs-image-thumbnail 18.0.1.0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| odoo_addon_fs_image_thumbnail-18.0.1.0.0.2-py3-none-any.whl | Python 3 | none | any | Details for odoo_addon_fs_image_thumbnail-18.0.1.0.0.2-py3-none-any.whl |
Release files / odoo_addon_fs_image_thumbnail-18.0.1.0.0.2-py3-none-any.whl
| Download URL | odoo_addon_fs_image_thumbnail-18.0.1.0.0.2-py3-none-any.whl |
|---|---|
| Size | 40.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
976742f684e5a92fc5d17ee45c8e699fab7cc8071f54ac3c966e5bee69a25e8c
|
|
BLAKE2b-256 checksum How to use checksums |
ccac8784c1139a47c84bab1c2ae9d7911c441a722efc91d4641e46d98ac5b4c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for odoo-addon-fs-image-thumbnail 18.0.1.0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.