Resizing Images on the Fly with PHP

“Why the hell am I writing articles in a blog?” That’s literally what I asked myself the other day. “Self,” I replied, “I want to help the world understand PHP and concepts of education better with the hopes making everyones lives better.”

“Liar,” I shot back… to myself, “You’re just getting old and want some place to put things you’ve figured out so you don’t forget them.”

Sigh.

So, in this episode of “Crap I Don’t Want To Figure Out Again”, I found myself in need of taking an image and resizing it using PHP. This isn’t a very common task for PHP, as developers usually have static images and service them in a typical fashion, so this took a bit of research.

I did, however, have a level of difficulty… These were ID badge photos coming out of a BLOB object in an Oracle database, all of which were different sizes and I needed a 100×100 image. The nice thing is that, since these were ID badge photographs, I could generally depend on the face being fairly centered in the image. The whole, “Getting a binary image out of a database to use” will be a different article, but this will handle taking an image and resizing it.