apache / incubator-pagespeed-mod

Apache module for rewriting web pages to reduce latency and bandwidth.
http://modpagespeed.com
Apache License 2.0
697 stars 158 forks source link

Resize images with alpha channel, especially if alpha channel is unused. #851

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Consider the following html:

<!DOCTYPE html>
<html>
  <body>
  <img src="https://master.chainels.com/images/111340925320370007_91372941797229515.png" alt="Software" title="Software" width="136" height="109">
  </body>
</html>

This image ought to be resized, but fails the test in image.cc:

  if (image_reader->GetPixelFormat() == RGBA_8888) {
    return false;
  }

But the alpha channel is unused, and we *ought* to be able to resize the image 
anyway.  It looks like the logic is messed up here in a few ways:

1) We should strip the unused alpha channel before attempting to resize.
2) GetOutputImageFormat is no longer correct.  It is only set based on the 
input format of the image and not based on the lossiness etc.
3) If the resizer works on images with an alpha channel, we should not reject 
them.  That should be true even if we would normally convert to jpeg afterwards 
– we wouldn't attempt to convert the original image to jpeg, we'd keep it a 
png, and we should do the same here and just resize it.

Original issue reported on code.google.com by jmaes...@google.com on 11 Dec 2013 at 7:13

GoogleCodeExporter commented 9 years ago
From 849:

If you look at the same page, 
https://www.chainels.com/111340925320370007/?p=about, there are 3 examples of 
those 136xN images in the center (look at the images that have the 'software', 
'websites', and 'ICT Consultancy' labels). For the Java image, for instance, 
the URL is 
https://master.chainels.com/image/136xNx111340925320370007_91372941797229515.png
.pagespeed.ic.J2cqc3iqEa.png, but the image remains 400x320 in size, a large 
difference.

Original comment by jmaes...@google.com on 11 Dec 2013 at 7:26

GoogleCodeExporter commented 9 years ago
It's time to clean up technical debt :) I left a "TODO" and now is the time to 
do it.

  // TODO(huibao): Enable resizing for WebP and images with alpha channel.
  // We have the tools ready but no tests.

Original comment by hui...@google.com on 11 Dec 2013 at 10:10

GoogleCodeExporter commented 9 years ago
Big Q here: was this fixed?  I thought it might have been.

Original comment by jmaes...@google.com on 16 Apr 2014 at 2:28

GoogleCodeExporter commented 9 years ago
No, it has not been fixed. I'll fix it while refactoring the code.

Original comment by hui...@google.com on 16 Apr 2014 at 2:32