summaryrefslogtreecommitdiff
path: root/odoo/tools/image.py
AgeCommit message (Collapse)Author
2019-02-14[IMP] tools,base,web: improve image toolsSébastien Theys
Add support for a 256*256 image, to be used in the following commit. Define sizes in named variables instead of being hard-coded in several places in the code. Allow parameters `preserve_aspect_ratio` and `upper_limit` to be passed from the different helper methods. Factorize the code inside `image_resize_images` to make it easier to read. Add new function to compute whether the size of an image is above a given size. task-34045 PR: #30656
2019-02-04[FIX] base: fixes http redirectionThanh Dodeur
The 7d85ab1eac6dbf33d56c6a1f8bf7e9e12bb8008e refactor of 'ir.http' introduced changes in `web/image` that caused the route to no longer return early (to avoid data processing steps) in the case of redirection and that caused `binary_content` to not set the mimetype of the `ir.attachment` when it was an URL. This commit fixes those issues, allowing `web/image` to redirect properly. closes odoo/odoo#30777
2018-12-06[REF] base, *: refactor binary_contentThanhDodeurOdoo
*: tools, web, website, website_forum, mail, im_livechat This commit refactors ir_http to make it more readable and flexible. Move the resize function of web/image to odoo.tools Co-authored-by: XavierDo <xdo@odoo.com> Co-authored-by: Antony Lesuisse <al@openerp.com> closes: #28563 task: #1908896
2018-11-29[REF] *: replace deprecated pycompat helpers for builtinsAdrian Torres
This commit replaces calls to pycompat helpers that were intended for python 2 <-> python 3 interoperability for python 3 builtins, as python 2 is no longer officially supported by Odoo. This includes: * calls to imap/izip/ifilter replaced by map/zip/filter * uses of text_type replaced by str * uses of unichr replaced by chr * calls to implements_to_string, implements_iterator removed * string_types and integer_types replaced by str, int respectively * calls to to_native replaced by calls to to_text This is done in preparation to the removal of these deprecated helpers in the following commit.
2018-10-03[ADD] *: replace hardcoded data URIs with helperPedro M. Baeza
- Add a method for generating an image data URI, and expose it in QWeb context - Fix reports, website templates or mail templates with data hardcoded data URIs, to use the helper (Python cases), or the existing kanban_image helper (for JS cases) This will gracefully handle SVG support in addition to classical image formats. Closes #26635
2018-10-03[ADD] *: support SVG imagesPedro M. Baeza
Introduce official support for SVG files in the framework, including the following parts: 1. When client-side SVG images are uploaded, the content is displayed until you save using data URI scheme according RFC 2397 [1]. This scheme requires to specify content format. Using hardcoded "image/png" works for all images types except SVG. Type-sniffing is done using "magic byte" detection via the first base64 encode byte, so that the proper data URI scheme can be used. This should not cause SVG-related security problems as the file is displayed through `<img>` tag, which does not allow SVG scripting [2]. 2. Make /web/image controller compatible with SVG 3. Add support for SVG files for company logo, which uses a dedicated controller. 4. Resizing of SVG files is a no-op, as it makes little sense for a vector-based format. We also want to avoid micro-alterations to the SVG document (in "natural" viewport parameters) as we would store multiple copies of the files in the filestore. 5. Because SVG files are inherently dangerous, upload of SVG files is restricted to administrators, either by blocking it directly before saving it in the database (binary fields with attachment=False), or by neutering them to text/plain mimetype (for binary fields with attachment=True) 6. Add tests for the SVG upload cases and for the non-admin uploads. [1] https://tools.ietf.org/html/rfc2397 [2] https://www.w3.org/wiki/SVG_Security Closes #26635
2018-09-07[MERGE] forward port branch saas-11.4 up to d78f23df848Christophe Simonis
2018-09-05[MERGE] forward port branch 11.0 up to 213759b03e5Christophe Simonis
2018-09-05[FIX] tools: image.crop_image default type fixThanhDodeurOdoo
- the image.crop_image method doesn't defaults the format to PNG anymore. Instead it uses the format of the original image and defaults to jpeg as a last resort as the save method requires a type if it is called with an image object.
2018-08-27[FIX] tools:image: reset stream on cropLucas Perais (lpe)
When cropping the image with a size, we crop it first and then we make a thumbnail out of it Before this commit, the same byte stream was used, meaning that the thumbnail was appended to the original After this commit, we reset the stream OPW 1876496 closes #26575
2018-08-13[IMP] base,mail,web: attachments adaptation for documentsThanhDodeurOdoo
This commit is the counter-part of an enteprise commit introducing the Documents app. Here is a summary of what has been done: - tweak unlink of ir_attachment to prevent unlink recursivity (when attachments are attached to ir_attachments) - improve ir_attachment kanban view - add several arguments to binary_content controller: - 'force_ext': to force the extension in the filename, base on mimetype - 'share_token' and 'share_id': to autorize download from a share link - add 'thumbnail' field on ir_attachment to optimize Kanban view - add 'upper_limit' argument to image to allow to bypass the 500*500 size limit - DocumentViewer now handles text files More information available on task 1853490 Co-authored-by: Pierre Paridans <app@odoo.com> Co-authored-by: sri-odoo <sri@odoo.com> Co-authored-by: ThanhDodeurOdoo <tso@odoo.com>
2018-03-15[IMP] base: resize partner image with actual aspect ratioSagar Ahirrao
Purpose of this commit is to finally stop adding extra padding to website logo. Indeed not giving square logos lead to padding added to images, leading to not so beautiful logo that makes people sad. Before this commit * partner's image was resized to square 1024x1024. Extra padding was added if user provided rectangle image; * due to this website logo resized to square when rectangle logo provided; After this commit, * sizes dict can be passed in image resizer of tools; * e.g. tools.image_resize_images(vals, sizes={'image': (512, 512), 'image_small': (128, 128)}) * image field in partner will resize with max width 1024 and height based on given image ratio (still image_medium, image_small will be default square images); * now website logo will respect actual aspect ratio This commit is related to task ID 31994 . Future commits should probably clean all that mess, but at least it seems we have something that works.
2017-12-06[MERGE] forward port branch 11.0 up to f96a797fe62Christophe Simonis
2017-12-05[FIX] product: image changes not sticking everywhereXavier Morel
Fixes #20046 Simply reverting e5ef1c59172b7b8ebb1912e015fd41003ffc275d looks to work *but* since I didn't note the repro case for the issue and don't remember what it was it may re-introduce previous breakage. Instead, ensure all "sizes" for the image are reset if any of the sizes is present *and* Falsy by adding a final case to the conditional. If any of the image fields is present and non-falsy one of the previous branches will be taken, so we can just check that any of the image fields is present at all (this implies it's falsy).
2017-10-25[IMP] tools: basic spelling and grammar correctionsAndrew Latham
Closes #20391
2017-09-12[MERGE] forward port branch saas-17 up to d08b4407be3Christophe Simonis
2017-09-07[FIX] P3: resizing of image *fields*Xavier Morel
Fields sent from the client are pretty much always *text*. This can be problematic for image fields sent as base64 *text* as in Python 3 the base64 routines only work between bytes. Alter the core field-resizing function (image_get_resized_images) such that it ensures text base64 sources are encoded back to bytes before being forwarded to the main resizing routines (which I don't think should deal with *that* issue). Fixes #18985: error when trying to update a company's logo
2017-09-05[IMP] image.py: Make 6801baa work in python3Yannick Tivisse
2017-09-05[IMP] image.py: Crop image with maximum size instead of ratioYannick Tivisse
Purpose ======= It makes no sense to crop an image from a ration. We don't say "I don't know my image size, but divide it by 2" Specification ============= Pass a maximum size argument instead of a thumbnail ratio
2017-08-20[FIX] P3: fix base64 and StringIO usesXavier Morel
* StringIO removed from stdlib, replace with io * try to correctly handle BytesIO/StringIO (one is for bytes the other is for text) * fix base64: Python 3 removed bytes-encoding and bytes-bytes codecs (via #encode) so replace all calls to str.encode('base64'), also b64encode is a bytes->bytes conversion so attempt to properly handle that issue #8530
2017-08-19[FIX] P3: / has become 'real division' in all casesXavier Morel
2017-07-07[MERGE] forward port branch saas-16 up to 0f2b2c4e2b9Christophe Simonis
2017-07-07[MERGE] forward port branch saas-15 up to 514a1a76d81Christophe Simonis
2017-07-07[MERGE] forward port branch saas-11 up to 96fa86779b1Christophe Simonis
2017-05-22[FIX] P3: don't resize the value FalseXavier Morel
Yields really strange errors in P3.
2017-05-16[MERGE] Forward-port saas-15 up to 878fbc75ff9ebade92f43748500e64350367a824Olivier Dony
2017-05-05[FIX] tools: always preload PIL with basic formatsOlivier Dony
Ensures that only the desired list of images formats are made available via PIL: BMP, GIF, PNG, JPEG, TIFF and PPM.
2017-04-27[FIX] builtins removed from Python 3xmo-odoo
* Reverse wrapper courtesy of @rco-odoo's original P3 branch * thin compat module stripped down from werkzeug (to augment as needed) issue 8530
2017-01-23[MERGE] forward port branch saas-11 up to b9374d5c215Christophe Simonis
2016-09-02[REF] openerp: move `openerp` to `odoo`Raphael Collet