Package: odoo-addon-fs-image-thumbnail
This module extends thefs_imageaddon to support the creation and the storage of
thumbnails for images. This module is atechnical moduleand 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.ImportantThis 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 statusTable of contentsUse Cases / ContextUsageChangelogBug TrackerCreditsAuthorsContributorsOther creditsMaintainersUse Cases / ContextIn 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 thefs_imagemodule to store the thumbnails in a filesystem storage.Theshopinvader_product_imageaddon uses this module to generate and
store the thumbnails of the images of the products and categories to be accessible
by the website.UsageThis addon provides a convenient way to get and create if not exists image
thumbnails. All the logic is implemented by the  abstract modelfs.image.thumbnail.mixin. The main method isget_or_create_thumbnailswhich
accepts aFSImageValueinstance, 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.Thefs.thumbnailmodel provided by this addon is a concrete implementation of
the abstract modelfs.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 thefs.storageform view.Creating / retrieving thumbnails is as simple as:fromodoo.addons.fs_image.fieldsimportFSImageValue# create an attachment with a image fileattachment=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 attachmentimage_value=FSImageValue(attachment)# get or create the thumbnailsthumbnails=self.env['fs.thumbnail'].get_or_create_thumbnails(image_value,[(800,600),(400,200)],'my base name')If you’ve a model with aFSImagefield, the call toget_or_create_thumbnailsis even simpler:fromodooimportmodelsfromodoo.addons.fs_image.fieldsimportFSImageclassMyModel(models.Model):_name='my.model'image=FSImage('Image')my_record=cls.env['my.model'].create({'image':open('test.png','rb'),})# get or create the thumbnailsthumbnails=record.image.get_or_create_thumbnails(my_record.image,[(800,600),(400,200)],'my base name')Changelog16.0.1.0.1 (2023-10-04)BugfixesThe call to the methodget_or_create_thumbnailson thefs.image.thumbnail.mixinclass 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 TrackerBugs are tracked onGitHub 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 welcomedfeedback.Do not contact contributors directly about support or help with technical issues.CreditsAuthorsACSONE SA/NVContributorsLaurent Mignon <laurent.mignon@acsone.eu> (https://acsone.eu)Other creditsThe development of this module has been financially supported by:Alcyon BeluxMaintainersThis 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.Currentmaintainer:This module is part of theOCA/storageproject on GitHub.You are welcome to contribute. To learn how please visithttps://odoo-community.org/page/Contribute.