Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] tools,base,*: improve image tools #31811

Open
wants to merge 14 commits into
base: master
from

Conversation

Projects
None yet
5 participants
@seb-odoo
Copy link
Contributor

seb-odoo commented Mar 13, 2019

Merge commit for PR: #31811

The main goal is to keep the image ratio on resize (instead of adding a white border).

The opportunity is taken to also clean up the image tools.

See individual commit messages for more information.

task-1958000

@seb-odoo seb-odoo self-assigned this Mar 13, 2019

@robodoo robodoo added the seen 🙂 label Mar 13, 2019

@seb-odoo seb-odoo force-pushed the odoo-dev:master-image-web-seb branch 2 times, most recently Mar 13, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Mar 13, 2019

@seb-odoo seb-odoo force-pushed the odoo-dev:master-image-web-seb branch Mar 13, 2019

@seb-odoo seb-odoo changed the title [IMP] tools: clean up image encoding Improve image tools Mar 13, 2019

@seb-odoo seb-odoo force-pushed the odoo-dev:master-image-web-seb branch Mar 13, 2019

@seb-odoo seb-odoo force-pushed the odoo-dev:master-image-web-seb branch Mar 13, 2019

@seb-odoo seb-odoo force-pushed the odoo-dev:master-image-web-seb branch Mar 13, 2019

@robodoo robodoo added the CI 🤖 label Mar 13, 2019

@seb-odoo seb-odoo force-pushed the odoo-dev:master-image-web-seb branch Mar 13, 2019

@robodoo robodoo removed the CI 🤖 label Mar 13, 2019

@seb-odoo seb-odoo force-pushed the odoo-dev:master-image-web-seb branch Mar 13, 2019

@seb-odoo seb-odoo force-pushed the odoo-dev:master-image-web-seb branch Mar 13, 2019

@seb-odoo seb-odoo force-pushed the odoo-dev:master-image-web-seb branch Mar 13, 2019

seb-odoo added a commit to odoo-dev/odoo that referenced this pull request Mar 25, 2019

[IMP] website_sale: center images in cart popup and right panel
If the images are not all square, it looks better if they are centered.

task-1958000
PR: odoo#31811

seb-odoo added a commit to odoo-dev/odoo that referenced this pull request Mar 25, 2019

[IMP] http,web,*: create set_header_field helper
* = website_profile, website_slides

The previous method `force_contenttype` was too specific and it wasn't available
in every controller. It didn't even need to be a controller method because it
didn't use self.

Now we create a generic helper `set_header_field` to ease updating headers.

task-1958000
PR: odoo#31811

seb-odoo added a commit to odoo-dev/odoo that referenced this pull request Mar 25, 2019

[IMP] tools,website: correctly handle favicon and .ico files
Previously the image that we uploaded as a favicon of the website was not
resized, so it could be extremely excessive in size and resolution, and it also
was not guaranteed to be a square.

Now we always resize it appropriately and save it as an ICO file.

The default favicon is now applied to all websites instead of only the first.

task-1958000
PR: odoo#31811

@robodoo robodoo added the CI 🤖 label Mar 25, 2019

@seb-odoo seb-odoo force-pushed the odoo-dev:master-image-web-seb branch from d6051b0 to 5058bff Mar 26, 2019

seb-odoo added a commit to odoo-dev/odoo that referenced this pull request Mar 26, 2019

[IMP] tools,base,*: merge all image tools
* = web, website_profile, website_slides

Make the image tools more consistent and easier to maintain by having a single
function handling all the cases, instead of several functions doing more or less
the same thing with obscure differences.

Also introduce a new function to guess the size based on a field name, to be
used in the following commit.

task-1958000
PR: odoo#31811

seb-odoo added a commit to odoo-dev/odoo that referenced this pull request Mar 26, 2019

[IMP] tools,base,*: remove intermediary image functions
* = hr, im_livechat, mail, payment, purchase, web, web_editor, web_unsplash,
	website_profile, website_slides

Since the merge of all image tools into one function, the intermediary functions
are not needed anymore.

task-1958000
PR: odoo#31811

seb-odoo added a commit to odoo-dev/odoo that referenced this pull request Mar 26, 2019

[FIX] web,*: return the correct Content-Type for images
* = web_unsplash, website_profile, website_slides

Before this commit, the returned Content-Type was not always correct, for
example if the image tool was changing the format, which happened when given
a BMP (converted to PNG), or other types being converted to JPEG.

task-1958000
PR: odoo#31811

seb-odoo added a commit to odoo-dev/odoo that referenced this pull request Mar 26, 2019

[IMP] base,web: adapt kanban image following image tools changes
Since the images are not guaranteed to be square anymore, the kanban image had
to be adapted to better handle the different image ratios.

Also the placeholder has been moved into the actual image div instead of
being a separate div that acted differently.

The avatar placeholder was white... displayed on top of white. Now it's grey
so we can actually see it.

task-1958000
PR: odoo#31811

seb-odoo added a commit to odoo-dev/odoo that referenced this pull request Mar 26, 2019

[IMP] base: clean up image tools tests
Since all the tools have been merged into one, the tests can be restructured and
the duplicate tests removed.

task-1958000
PR: odoo#31811

seb-odoo added a commit to odoo-dev/odoo that referenced this pull request Mar 26, 2019

[IMP] website_sale: center images in cart popup and right panel
If the images are not all square, it looks better if they are centered.

task-1958000
PR: odoo#31811

seb-odoo added a commit to odoo-dev/odoo that referenced this pull request Mar 26, 2019

[IMP] http,web,*: create set_header_field helper
* = website_profile, website_slides

The previous method `force_contenttype` was too specific and it wasn't available
in every controller. It didn't even need to be a controller method because it
didn't use self.

Now we create a generic helper `set_header_field` to ease updating headers.

task-1958000
PR: odoo#31811

seb-odoo added a commit to odoo-dev/odoo that referenced this pull request Mar 26, 2019

[IMP] tools,website: correctly handle favicon and .ico files
Previously the image that we uploaded as a favicon of the website was not
resized, so it could be extremely excessive in size and resolution, and it also
was not guaranteed to be a square.

Now we always resize it appropriately and save it as an ICO file.

The default favicon is now applied to all websites instead of only the first.

task-1958000
PR: odoo#31811

@robodoo robodoo removed the CI 🤖 label Mar 26, 2019

seb-odoo added some commits Mar 25, 2019

[IMP] tools,base: remove image encoding parameter
The image tools were accepting an encoding parameter but it was never used.
Indeed the given images are always encoded in base64.

`image_colorize` was the only method not taking base64 directly, so it has been
modified for consistency. This allows to change the code in partner to not
base64 decode the image in some case just to be base64 encode it again after.

This commit also takes the opportunity to rename the filter ANTIALIAS to LANCZOS
(new name since Pillow 2.7.0).

Finally the "ghost border fix" has been removed because we can't reproduce the
issue it was trying to solve.

task-1958000
PR: #31811
[IMP] tools,web_editor,web_unsplash: improve image optimize for web
This commit introduces the possibility to resize and to select the quality when
optimizing an image for web.

This will be used by the media dialog in a future commit.

The arbitrary resolution limit of 42e6 has been increased to 45e6 to fit some
of the biggest images we might get from Unsplash, and this value has been moved
into a variable so it can be customized.

task-1958000
PR: #31811
[IMP] web,website_profile,website_slides: rename content and base64
There is a mix in the variable names: before this commit, what is called
`image_base64` is actually not base64 encoded, and what is called `content` is
actually base64 encoded.

The variables have been renamed to avoid further confusion.

task-1958000
PR: #31811
[IMP] tools,base,*: keep image ratio on resize
* = web, website_partner, website_profile, website_sale, website_slides

Before
======

Since commit: 2e3848b

The images that are resized have additional borders if the target ratio is
different than the image ratio. Those borders are transparent if the image
format supports it, and are white otherwise.

With that current solution, if the background where the image is displayed is
another color than white, it is looking really bad.

Moreover, most images are stored resized like this, so it is not even possible
to decide if it should have borders or not depending on the context, the
original image and ratio is forever lost.

It is also inconsistent because if the image is already smaller than the target
size then it doesn't include borders. In that case it keeps the original ratio
instead of the target ratio. So it isn't even guaranteed that the target
ratio is going to be respected.

After
=====

This commit will solve all of those problems by always keeping the ratio of the
original image.

This implies the views should be taking care of adding borders when necessary.

task-1958000
PR: #31811
[IMP] tools,base: remove ratio from image crop
Following commit: 6801baa

Crop is always used when we know the target size. Therefore there is no point
to pass a ratio argument. However size is required now.

Also "center" is always used, so make it the default type.

task-1958000
PR: #31811
[IMP] tools,base,*: merge all image tools
* = web, website_profile, website_slides

Make the image tools more consistent and easier to maintain by having a single
function handling all the cases, instead of several functions doing more or less
the same thing with obscure differences.

Also introduce a new function to guess the size based on a field name, to be
used in the following commit.

task-1958000
PR: #31811
[IMP] tools,base,*: remove intermediary image functions
* = hr, im_livechat, mail, payment, purchase, web, web_editor, web_unsplash,
	website_profile, website_slides

Since the merge of all image tools into one function, the intermediary functions
are not needed anymore.

task-1958000
PR: #31811
[FIX] web,*: return the correct Content-Type for images
* = web_unsplash, website_profile, website_slides

Before this commit, the returned Content-Type was not always correct, for
example if the image tool was changing the format, which happened when given
a BMP (converted to PNG), or other types being converted to JPEG.

task-1958000
PR: #31811
[IMP] base,web: adapt kanban image following image tools changes
Since the images are not guaranteed to be square anymore, the kanban image had
to be adapted to better handle the different image ratios.

Also the placeholder has been moved into the actual image div instead of
being a separate div that acted differently.

The avatar placeholder was white... displayed on top of white. Now it's grey
so we can actually see it.

task-1958000
PR: #31811
[IMP] base: clean up image tools tests
Since all the tools have been merged into one, the tests can be restructured and
the duplicate tests removed.

task-1958000
PR: #31811
[IMP] website_sale: center images in cart popup and right panel
If the images are not all square, it looks better if they are centered.

task-1958000
PR: #31811
[IMP] http,web,*: create set_header_field helper
* = website_profile, website_slides

The previous method `force_contenttype` was too specific and it wasn't available
in every controller. It didn't even need to be a controller method because it
didn't use self.

Now we create a generic helper `set_header_field` to ease updating headers.

task-1958000
PR: #31811
[IMP] tools,website: correctly handle favicon and .ico files
Previously the image that we uploaded as a favicon of the website was not
resized, so it could be extremely excessive in size and resolution, and it also
was not guaranteed to be a square.

Now we always resize it appropriately and save it as an ICO file.

The default favicon is now applied to all websites instead of only the first.

task-1958000
PR: #31811

@seb-odoo seb-odoo force-pushed the odoo-dev:master-image-web-seb branch from 5058bff to a9c03b4 Mar 26, 2019

@robodoo robodoo added the CI 🤖 label Mar 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.