================== Fs Image Thumbnail ================== .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:ae84af058fd490c7c8916156dc7db31813b6d5f7535e722740b152d6955e0d57 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png :target: https://odoo-community.org/page/development-status :alt: Alpha .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github :target: https://github.com/OCA/storage/tree/16.0/fs_image_thumbnail :alt: OCA/storage .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png :target: https://translation.odoo-community.org/projects/storage-16-0/storage-16-0-fs_image_thumbnail :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png :target: https://runboat.odoo-community.org/builds?repo=OCA/storage&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| 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. .. IMPORTANT:: This is an alpha version, the data model and design can change at any time without warning. Only for development or testing purpose, do not use in production. `More details on development status `_ **Table of contents** .. contents:: :local: 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: .. code-block:: python 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, [(800,600), (400, 200)], 'my base name') If you've a model with a *FSImage* field, the call to `get_or_create_thumbnails` is even simpler: .. code-block:: python 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, [(800,600), (400, 200)], '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 ======= Authors ~~~~~~~ * ACSONE SA/NV Contributors ~~~~~~~~~~~~ * Laurent Mignon (https://acsone.eu) Other credits ~~~~~~~~~~~~~ The development of this module has been financially supported by: * `Alcyon Belux `_ Maintainers ~~~~~~~~~~~ This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org 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. .. |maintainer-lmignon| image:: https://github.com/lmignon.png?size=40px :target: https://github.com/lmignon :alt: lmignon Current `maintainer `__: |maintainer-lmignon| 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.