Current time: 12-16-2017, 07:43 AM Hello There, Guest! (LoginRegister)

Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Apache/PHP Image Compression
10-24-2011, 11:56 PM
Post: #1
Apache/PHP Image Compression
Does anyone know of a good option for compressing images via PHP? I'm about to test with the latest version of Imagick, but am looking around for other options. Currently migrating our site over to a better server setup and so now is the best time to investigate such solutions.
Basically we have a photography department here for taking photos of each product that comes in before being listed online (this is for an ecommerce site). I have them running the images through batch scripts to properly compress them via "save for web" and then they upload the images from there. While this is fine, we have issues where they will temporarily upload images from the manufacturers website before replacing it with ones we took, but these images are not always optimized properly. I've seen occasions where the thumbnail size for a 100x100 image was 18 KB! Now, this is with a super old version of Imagick, i'm hoping the newest version is better at compressing. But, while i'm testing that i'm open to other suggestions while i'm at it.
Thanks!
Find all posts by this user
Quote this message in a reply
10-27-2011, 09:12 AM
Post: #2
RE: Apache/PHP Image Compression
We use a two step process.
1. We use http://www.imagemagick.org/script/index.php with 85% compression rate.
2. we apply a lossless compressioin that strip all meta data using jpegtran.exe
In jpegtran, use the -copy none -optimized for images < 10k and -copy none -progressive on image > 10k

If you don't mind doing a little manual work, you can use http://www.jpegmini.com. It does a really good job compressing jpg and then running #2 on top.

If you want to optimize even further, than you can use webP compression for images. It's native for chrome users, but people using IE of FF will have to install the "codec". All the info can be found here: http://code.google.com/speed/webp/

Hope this helps
Find all posts by this user
Quote this message in a reply
11-01-2011, 02:58 AM
Post: #3
RE: Apache/PHP Image Compression
Solution from the Yahoo Performance Team Best Practices on how to optimize images:
  • You can check the GIFs and see if they are using a palette size corresponding to the number of colors in the image. Using imagemagick it's easy to check using
    identify -verbose image.gif
    When you see an image useing 4 colors and a 256 color "slots" in the palette, there is room for improvement.
  • Try converting GIFs to PNGs and see if there is a saving. More often than not, there is. Developers often hesitate to use PNGs due to the limited support in browsers, but this is now a thing of the past. The only real problem is alpha-transparency in true color PNGs, but then again, GIFs are not true color and don't support variable transparency either. So anything a GIF can do, a palette PNG (PNG8) can do too (except for animations). This simple imagemagick command results in totally safe-to-use PNGs:
    convert image.gif image.png
    "All we are saying is: Give PiNG a Chance!"
  • Run pngcrush (or any other PNG optimizer tool) on all your PNGs. Example:
    pngcrush image.png -rem alla -reduce -brute result.png
  • Run jpegtran on all your JPEGs. This tool does lossless JPEG operations such as rotation and can also be used to optimize and remove comments and other useless information (such as EXIF information) from your images.
    jpegtran -copy none -optimize -perfect src.jpg dest.jpg

All the tools listed are available as comand line tools so you just have to install these and call them in a PHP script.
Visit this user's website Find all posts by this user
Quote this message in a reply
11-01-2011, 03:57 AM
Post: #4
RE: Apache/PHP Image Compression
Thanks, I will check out those tools.
Find all posts by this user
Quote this message in a reply
02-05-2012, 03:08 AM
Post: #5
RE: Apache/PHP Image Compression
I'd just like to say thanks to mrPerezMarc and allogarage for their tips, I've been looking for a good way to compress images via PHP (toying with Imagick) on behalf of a client for half the day - finally managed to put something together everyone is happy with!

I'm debating about compressing some with webP, but until Google takes over the world I fear of alienating my FF/IE userbase...
Find all posts by this user
Quote this message in a reply
02-06-2012, 11:17 PM
Post: #6
RE: Apache/PHP Image Compression
@SpyGrey, I believe the browsers that support webP send an accept header that indicates it. You could serve webP to browsers that support it and fall back to jpeg for browsers that don't (though you'd want to add a vary header so proxies don't cache the wrong image type).
Visit this user's website Find all posts by this user
Quote this message in a reply
02-10-2012, 06:33 PM (This post was last modified: 02-13-2012 01:18 PM by Habbakuk1.)
Post: #7
RE: Apache/PHP Image Compression
After I tested my website, the un-optimized images would only save a minimal amount if I compressed them, but as I have a large e-commerce website, I would like some sort of solution to automatically compress all my images.
replica watches replica watch replica watches replica watch swiss watch replicas
Also, thanks a lot mrPerezMarc, http://www.jpegmini.com looks absolutely awesome. I've used a few really good jpg optimizers online, but I'm extremely excited to see if this website can top them. edit: it kinda annoying that they dont let you pick various stages of optimization, instead giving you just one choice only.
Find all posts by this user
Quote this message in a reply
02-16-2012, 08:58 AM
Post: #8
RE: Apache/PHP Image Compression
Glad my advice helped Smile
Find all posts by this user
Quote this message in a reply
03-29-2012, 02:41 AM
Post: #9
RE: Apache/PHP Image Compression
Actually there is such a thing as animated pngs nowadays.

http://en.wikipedia.org/wiki/APNG

[Image: Animated_PNG_example_bouncing_beach_ball.png]

[Image: Brain_MRI_apng_105px_100ms.png]

(11-01-2011 02:58 AM)allogarage Wrote:  [*] Try converting GIFs to PNGs and see if there is a saving. More often than not, there is. Developers often hesitate to use PNGs due to the limited support in browsers, but this is now a thing of the past. The only real problem is alpha-transparency in true color PNGs, but then again, GIFs are not true color and don't support variable transparency either. So anything a GIF can do, a palette PNG (PNG8) can do too (except for animations). This simple imagemagick command results in totally safe-to-use PNGs:
Visit this user's website Find all posts by this user
Quote this message in a reply
03-29-2012, 02:53 AM
Post: #10
RE: Apache/PHP Image Compression
APNGs are not supported on most browsers, so I think it's a bad idea to use these for now.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)