plone / Products.CMFPlone

The core of the Plone content management system
https://plone.org
GNU General Public License v2.0
251 stars 188 forks source link

PLIP: Retina image scales #1483

Closed ghost closed 7 years ago

ghost commented 8 years ago

Proposer : Diederik Veeze

Seconder : Maurits van Rees

Abstract

Scale images in plone.scale such that they will look good on devices with pixel ratios higher than 1.

Motivation

More and more devices these days can display images with higher resolution than the html/css resolution. Plone however often serves images that are scaled to the exact same size as html/css resolution, while a lot of devices can display twice the resolution.

Assumptions

N/A

Proposal & Implementation

I propose to add an option to the imaging control panel to set a pixel ratio for image scaling. Images generated in plone.scale will generate images whose height and width are multiplied by this pixel ratio. For instance an image in the site of 320x240 with a scaling factor of 2 should result in something like the following: <img src="someimage-640x480.jpeg" alt="Some Image" width="320" height="240">

Deliverables

The image scales will get larger, but the image quality for these larger scales can be reduced while still giving a satisfactory result, for only a small increase in byte size.

Participants

@mauritsvanrees

Note

I recently signed the contributor assignment agreement and am awaiting confirmation.

mauritsvanrees commented 7 years ago

I have rebased CMFPlone and p.a.upgrade and started the Jenkins job again.

mauritsvanrees commented 7 years ago

There were a few failing tests, but I fixed them and the plip job is green now.

thet commented 7 years ago

Here are some screenshots showing the improvement with Retina image scales on and off on a Laptop with 4k display.

You have to click on the images to open them fullscreen to see the difference.

Although the original scale has a higher quality setting, the 2x version with the lower quality setting which is used by the browser and scaled down is much better.

News Item retina off: screen shot 2017-03-16 at 12 57 40

News Item retina on: screen shot 2017-03-16 at 12 57 19

Image retina off: screen shot 2017-03-16 at 12 56 08

Image retina on: screen shot 2017-03-16 at 12 57 02

thet commented 7 years ago

More test results - these are the images including their size:

Inline news image 1x, 8,7 kB: n1-9ff7a15f-9b29-4322-8369-970a085369fc

Inline news image 2x, 17,5 kB: n2-22165690-5d96-4178-b169-af352871cde3

Inline news image 3x, 31,8 kB: n3-ca6e1114-97e4-4b0a-b7d2-5232c2619009

Image 1x, 118,3 kB: img1-3df51e25-73b3-47d4-8484-e3c8025a0f55

Image 2x, 245,9 kB: img2-891ced86-5bc6-4e52-954d-1a5e59f4ca17

Image 3x, 455,5 kB: img3-52d4f3da-14c9-489f-9bcc-8fb802b88747

Original Image, 5.5 MB: Github doesn't scale down for the preview and includes 5.5 MB, so I removed the picture.

Pics © by me, Johannes Raggam

thet commented 7 years ago

@mauritsvanrees I have added a review here: https://github.com/plone/buildout.coredev/blob/5.1/plips/reviews/plip1483-retina-image-scales-review-thet.rst

thet commented 7 years ago

By the way: The pics above show the "Which Hat Tower" in Minneapolis. Beautiful neighbourhood.

hvelarde commented 7 years ago

awesome, guys! I can't wait to test lazysizes with this new feature.

jensens commented 7 years ago

My review is ready and available at https://github.com/plone/buildout.coredev/blob/5.1/plips/reviews/plip1483-retina-image-scales-review-jensens.rst

mauritsvanrees commented 7 years ago

@jensens Did you commit and push your changes to the review? The last change to that file was two weeks ago.

jensens commented 7 years ago

ops, need to read more careful the console output, now its on GitHub

thet commented 7 years ago

@mauritsvanrees I just updated my review with a code-review section about adapterization of plone.namedfile.scaling.ImageScale. This is a non-blocker, but I want to raise awareness (and not loose my thoughts while reviewing) about an issue I might need an answer to sometime soon.

Second thing, re-reading this thread, I found that you already mentioned an imagetag view with some critical thoughts about it. I mentioned the same in my review. Funny thing, I thought I came up with that idea while reviewing your code :)

mauritsvanrees commented 7 years ago

As for testing in the wild: you can see the srcset attributes in use on the carousel of a client of Zest: Zeelandia International.

jensens commented 7 years ago

merged!

jensens commented 7 years ago

Thanks for the great work!

fgrcon commented 7 years ago

Phantastic / I am merging with PLIP https://github.com/plone/Products.CMFPlone/issues/1734 right now. I found still some locations to upgrade:

furthermore

How should this work with TinyMce ... ?

mauritsvanrees commented 7 years ago

Thanks for the reviews and the merge. Glad to have this finally in core. Thanks to colleague @didrix who did most of the work and figuring things out. Congrats on the merge!

So, reading the reviews and final comments, it seems there may be room for some extra fixes or ideas:

fgrcon commented 7 years ago

Update plone.app.contenttypes.image.pt. This already uses the tag function, so seems good already.

sorry I uploaded too small images, works fine!"