Thursday, June 2, 2016

centos - How to prevent compression of images served via HTTP



I have an already optimized JPEG image in my server 32.07 kB (and in my local computer), 800px * 534px, if I request it via browser, it keeps the same width * height, but its size gets smaller 17,97 Ko and becomes pixelated.



I checked Apache configuration:




# LoadModule deflate_module modules/mod_deflate.so



Response Headers:




HTTP/1.1 200 OK
Date: Sat, 30 Jan 2016 11:31:50 GMT
Server: Apache
Last-Modified: Sat, 26 Dec 2015 11:56:02 GMT
ETag: "804c-527cbc1833880"

Accept-Ranges: bytes
Content-Length: 32844
Content-Type: image/jpeg
Connection: keep-alive


I am working on a LAMP environment installed on a VPS server. I sent a ticket to OVH to ask them if they are compressing images on a superior level, but still waiting for a response.



Are there other places to inpect instead of Apache ?




Another thing, I can bet it's not related to browser, because I got the same result in Firefox and Chrome.


Answer



Compressed or Not Compressed



Content-Length: 32844 matches the size of your jpeg and there is no header saying the file is compressed. I assume you also tested this from your workstation?



How you verify



Use curl or wget to pull the image to your computer and validate the size has not changed, assuming your connection is HTTPS and nothing else can intercept the communication such as a proxy or anti-virus. Proxies can most certainly change the size of images.




Proxy Testing



Assuming you have mod_headers module in your apache installation, add the following to your apache config to tell Proxies to leave the file alone.



header set cache-control "private, max-age=0, no-cache, no-transform, no-store"
header set Pragma no-cache


This should go in a section specific to the jpeg you are testing.




Keep in mind that any content served up with these headers will not be cached and performance will suffer. It may be worth reading up on cache-control headers.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...