Skip to main content

Posts

Showing posts from March, 2013

Responsive Images On-The-Fly with PHP and ImageMagick

I've seen some responsive image solutions proposed, and they seem great. But there's still some debate and it will be a while before support is widespread. In the meantime, I've expanded on a method I've been using for re-sizing images on the fly, which I believe can be further expanded on to make it even better. Basically, I use a PHP script and ImageMagick to generate a re-sized and cropped image, which I also cache for later use. Here's the essentials of the script I'm using: Using this script, I can request re-sized images via JavaScript, or even CSS (presuming the image is in a background) based on the current screen resolution and pixel density. This may not be the most elegant solution, but it's worked fairly well for me. For the purpose of this example, assume this script resides at domain.com/tools/ Note: This is an untested adaptation of a working script. It may not work as-is. $file = urldecode($_GET['f']); $widt