-
Notifications
You must be signed in to change notification settings - Fork 192
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
Upload thumbnails are blurry #1942
Comments
@karlcow what do you think? |
houla THAT is blurry. :) Some options:
I guess we worked out the quality in #1267 |
ah no #710 is where we tested the quality/time. |
that would be a very cool 2018Q1 goal if we were going the out of band version. Option 1. We can try to improve a bit more the parameters. I need to do more tests. Probably 1 day of work testing options. |
We are using Pillow 4.0.0
|
let me try this image https://staging.webcompat.com/issues/1308 again locally. Running on
12.2.0 version
Upgrading to pillow 5.2.0
And redoing a upload test. It didn't change anything. And the sizes are identical
Maybe we can tweak a bit the quality parameters. Dropping the
|
if self.image_object.format in ['JPEG', 'JPG', 'JPE', 'PNG']: | |
save_parameters['optimize'] = True |
- Image.save
- JPEG parameters
If present and true, indicates that the encoder should make an extra pass over the image in order to select optimal encoder settings.
Quality didn't improve. Image is bigger.
-rw-rw-rw-@ 1 karl staff 203526 9 aoû 12:30 original-test.jpg
-rw-rw-rw-@ 1 karl staff 24233 9 aoû 12:30 original-thumbnail.jpg
-rw-rw-rw-@ 1 karl staff 24142 9 aoû 12:36 12.2.0-thumbnail.jpeg
-rw-rw-rw-@ 1 karl staff 24142 9 aoû 13:08 pillow-5.2.0-thumbnail.jpeg
-rw-rw-rw-@ 1 karl staff 26808 9 aoû 13:20 pillow-5.2.0-no-optimize-thumbnail.jpeg
Let's put optimize back.
tweaking the thumbnail quality parameter
webcompat.com/webcompat/api/uploads.py
Line 120 in 42781cc
self.image_object.thumbnail(size, Image.BILINEAR) |
Check the previous discussions about the quality parameters
Trying to re-run the tests from 2 years ago
→ python resize-filter.py
Traceback (most recent call last):
File "resize-filter.py", line 22, in <module>
original2.save(thumb_name, 'JPEG')
File "/Users/karl/.virtualenvs/webcompatcom/lib/python2.7/site-packages/PIL/Image.py", line 1950, in save
save_handler(self, fp, filename)
File "/Users/karl/.virtualenvs/webcompatcom/lib/python2.7/site-packages/PIL/JpegImagePlugin.py", line 623, in _save
raise IOError("cannot write mode %s as JPEG" % im.mode)
IOError: cannot write mode RGBA as JPEG
Interesting 🤔
Ah! Deprecated
Before Pillow 4.2.0, attempting to save an RGBA image as JPEG would discard the alpha channel. From Pillow 3.4.0, a deprecation warning was shown. From Pillow 4.2.0, the deprecation warning is removed and an :py:exc:
IOError
is raised.
I need to convert the image to RGB first. Probably something to add to our code too (for people uploading PNG image with an alpha channel), if we do not want to have bad surprises when switching to Pillow 5.2.0
new resize-filter script.
Things have improved a lot in terms of time. But new computer too… so we can't directly compare with the previous results. The convert to RGB adds only a minimal penalty, so we are safe for this.
This is testing the previous japantimes PNG image.
thumb_nearest.jpg:
creating thumbnail 0.0048 seconds
convert to RGB 0.0002 seconds
save thumbnail 0.0196 seconds
---------------------------------------------
total = 0.0246 seconds
thumb_bilinear.jpg:
creating thumbnail 0.0118 seconds
convert to RGB 0.0002 seconds
save thumbnail 0.0079 seconds
---------------------------------------------
total = 0.0199 seconds
thumb_bicubic.jpg:
creating thumbnail 0.0162 seconds
convert to RGB 0.0002 seconds
save thumbnail 0.0075 seconds
---------------------------------------------
total = 0.0239 seconds
thumb_lanczos.jpg:
creating thumbnail 0.0214 seconds
convert to RGB 0.0002 seconds
save thumbnail 0.008 seconds
---------------------------------------------
total = 0.0296 seconds
thumb_antialias.jpg:
creating thumbnail 0.0223 seconds
convert to RGB 0.0002 seconds
save thumbnail 0.0075 seconds
---------------------------------------------
total = 0.03 seconds
Let's try to test with @miketaylr image and resized at 700, 700 as on webcompat.
-rw-r--r-- 1 karl staff 29375 9 aoû 14:13 thumb_antialias.jpg
-rw-r--r-- 1 karl staff 28440 9 aoû 14:13 thumb_bicubic.jpg
-rw-r--r-- 1 karl staff 26808 9 aoû 14:13 thumb_bilinear.jpg
-rw-r--r-- 1 karl staff 29375 9 aoû 14:13 thumb_lanczos.jpg
-rw-r--r-- 1 karl staff 32410 9 aoû 14:13 thumb_nearest.jpg
and
thumb_nearest.jpg:
creating thumbnail 0.0021 seconds
convert to RGB 0.0007 seconds
save thumbnail 0.0117 seconds
---------------------------------------------
total = 0.0145 seconds
thumb_bilinear.jpg:
creating thumbnail 0.0272 seconds
convert to RGB 0.0001 seconds
save thumbnail 0.0118 seconds
---------------------------------------------
total = 0.0391 seconds
thumb_bicubic.jpg:
creating thumbnail 0.0438 seconds
convert to RGB 0.0002 seconds
save thumbnail 0.0119 seconds
---------------------------------------------
total = 0.0559 seconds
thumb_lanczos.jpg:
creating thumbnail 0.0626 seconds
convert to RGB 0.0002 seconds
save thumbnail 0.0125 seconds
---------------------------------------------
total = 0.0753 seconds
thumb_antialias.jpg:
creating thumbnail 0.0636 seconds
convert to RGB 0.0002 seconds
save thumbnail 0.0115 seconds
---------------------------------------------
total = 0.0753 seconds
Nearest is still the crappiest. The two best ones are: antialias and lanczos
antialias:
lanczos
Image size let see with 1024px instead of 700px
-rw-r--r-- 1 karl staff 50904 9 aoû 14:22 thumb_antialias.jpg
-rw-r--r-- 1 karl staff 49667 9 aoû 14:22 thumb_bicubic.jpg
-rw-r--r-- 1 karl staff 47195 9 aoû 14:22 thumb_bilinear.jpg
-rw-r--r-- 1 karl staff 50904 9 aoû 14:22 thumb_lanczos.jpg
-rw-r--r-- 1 karl staff 53802 9 aoû 14:22 thumb_nearest.jpg
thumb_nearest.jpg:
creating thumbnail 0.003 seconds
convert to RGB 0.0002 seconds
save thumbnail 0.0242 seconds
---------------------------------------------
total = 0.0274 seconds
thumb_bilinear.jpg:
creating thumbnail 0.0333 seconds
convert to RGB 0.0005 seconds
save thumbnail 0.0241 seconds
---------------------------------------------
total = 0.0578 seconds
thumb_bicubic.jpg:
creating thumbnail 0.0672 seconds
convert to RGB 0.0003 seconds
save thumbnail 0.0231 seconds
---------------------------------------------
total = 0.0906 seconds
thumb_lanczos.jpg:
creating thumbnail 0.0984 seconds
convert to RGB 0.0003 seconds
save thumbnail 0.0249 seconds
---------------------------------------------
total = 0.1235 seconds
thumb_antialias.jpg:
creating thumbnail 0.0782 seconds
convert to RGB 0.0003 seconds
save thumbnail 0.0245 seconds
---------------------------------------------
total = 0.103 seconds
Quality
The original image provided by mike is not heavy. I think I need to test with a very heavy image too.
Heavy image (2.3M)
-rw-r--r--@ 1 karl staff 2428979 9 aoû 14:32 tokyo-map.png
-rw-r--r-- 1 karl staff 152956 9 aoû 14:34 thumb_antialias.jpg
-rw-r--r-- 1 karl staff 146880 9 aoû 14:34 thumb_bicubic.jpg
-rw-r--r-- 1 karl staff 134872 9 aoû 14:34 thumb_bilinear.jpg
-rw-r--r-- 1 karl staff 152956 9 aoû 14:34 thumb_lanczos.jpg
-rw-r--r-- 1 karl staff 179750 9 aoû 14:34 thumb_nearest.jpg
thumb_nearest.jpg:
creating thumbnail 0.0132 seconds
convert to RGB 0.0008 seconds
save thumbnail 0.0518 seconds
---------------------------------------------
total = 0.0659 seconds
thumb_bilinear.jpg:
creating thumbnail 0.0303 seconds
convert to RGB 0.0009 seconds
save thumbnail 0.0341 seconds
---------------------------------------------
total = 0.0654 seconds
thumb_bicubic.jpg:
creating thumbnail 0.0489 seconds
convert to RGB 0.0009 seconds
save thumbnail 0.0359 seconds
---------------------------------------------
total = 0.0856 seconds
thumb_lanczos.jpg:
creating thumbnail 0.0627 seconds
convert to RGB 0.0009 seconds
save thumbnail 0.0351 seconds
---------------------------------------------
total = 0.0986 seconds
thumb_antialias.jpg:
creating thumbnail 0.0628 seconds
convert to RGB 0.0009 seconds
save thumbnail 0.035 seconds
---------------------------------------------
total = 0.0987 seconds
This is not too bad.
TO EXPLORE
Any take on this? Any feelings 😝 @miketaylr The doc contains a table for performance-quality comparison Maybe HAMMING is worth trying. Let's try a test with this. 700
hamming (700, 700) 1024
hamming (1024, 1024) |
… channel This was deprecated in 4.2.0 https://github.com/python-pillow/Pillow/blob/master/docs/releasenotes/4.2.0.rst#removed-deprecated-items and as we upgrade to 5.2.0, we need to take care of this case. see the discussion in python-pillow/Pillow#2609
HAMMING looks pretty good! 🐖 |
Not sure if we can tune the jpeg compression a bit -- I find the thumbnail image to be a little too blurry.
https://staging.webcompat.com/issues/1308 as an example.
The text was updated successfully, but these errors were encountered: