Photo Slideshow – Part One – Batch Resize

The idea is simple, I want to be able to upload a directory full of pictures and have a slideshow. I have a few groups of photos to share with the world and more and more I’m keen on the idea of coding it myself rather then use a service like flickr or Picasa.

The first step was to upload my photos. I created a directory ‘images’ and inside that directory I created ‘originals’ and ‘700w’. I then uploaded all my pictures to the originals directory.

I then created a script to automatically resize all the images in my directory.

<?php
//it can take a bit to resize a bunch of images..
//php will by default only run for 30 seconds
//this removes that limitation
set_time_limit(0);

//open our directory
if ($handle = opendir('images/originals')) {
    //go through our directory filenames one by one
    while (false !== ($file = readdir($handle))) {
        //ignore our . and .. directories
        if ($file != "." && $file != "..") {
            //open our image
            $image = imagecreatefromjpeg('images/originals/'."$file");
            if ($image === false) { closedir($handle); die ('Unable to open image'); }

            //get our original image dimensions
            $owidth = imagesx($image);
            $oheight = imagesy($image);

            //our new dimensions, hardcoded for a 700 width
            //second line adjusts the height to keep the same aspect ratio
            $nwidth = 700;
            $nheight =  $newheight=($oheight/$owidth)*$nwidth;

            //create a new blank image the right size
            $tmpimg=imagecreatetruecolor($nwidth,$nheight);
            //and resize/resample our original into it
            imagecopyresampled($tmpimg,$image,0,0,0,0,$nwidth,$nheight,$owidth,$oheight);

            //write to file
            $filename = "images/700w/". $file;
            imagejpeg($tmpimg,$filename);

            //clean up
            imagedestroy($image);
            imagedestroy($tmpimg);
        }
    }
    closedir($handle);
}
?>

I saved this as ‘resize.php’ and ran it with ‘php resize.php’. After about a minute my 700w directory was full of resized images, and I’m all set up for the slideshow I want.

Checklist for the Expecting Father

“Are you all ready for the pregnancy?” My boss asked.

“Sure, we have her clothes packed and the phone list ready…” I replied.

“No,” he cut me off, “are YOU ready for the pregnancy?”

He then went on with a list of things I personally never thought about. While the misses was going to have her day set, I would be sitting around either bored or playing helper. I thought I’d share some tips from my recent experience.

Food
Your going to be gone for at least 24 hours. You’ll probably be able to sneak away to the nearest grease joint, but who knows what the timing is going to be. My boss recommends cheese and crackers. I preferred cookies and chips.

Money
Of the loose kind. Grab a roll of quarters in advance to feed to the magic food dispensers. Your hospital will most likely have these conveniently located 19 floors and 7 closets away from where you’re at.

Pillow and Blanket
I recommend doing what I did and upon getting there immediately sleep if the misses is inducing. You’ll be able to catch a couple of hours before the storm hits. Catch as much sleep as you can without pissing off the misses. You probably won’t sleep much that first night as the baby will be crying throughout the night.

Clothing and Personal Hygiene
24 hours. So you’ll need your pit stick, a toothbrush and paste, and maybe a spare T-shirt. That would have came in handy as the first thing my daughter did was pee all over mine.

MP3 Player
Your going to need something to drown out the relatives when they all come and visit. They will ramble on incessantly about how their friend’s nephew’s father-in-law’s ex-wife’s daughter had this sort of birth with this sort of drugs. Just smile nod your head to the beat of Radiohead. Bring one for the misses as well.

Time Wasters
Perhaps puzzle books or a laptop. Our room had a DVD player in it and if we had known/thought ahead of time we could have been watching cool animes on our crappy TV.

Patience
Just smile and nod. It’ll be over soon enough. Mom’s gonna scream, yell, curse, cringe, moan and complain. If the drugs don’t work you’ll have to deal with this the whole time. If they do work you have to deal with loopy Mom which is almost as bad. Just smile, nod, and persevere.

A Sidecar Mentality
As the father of this baby you have absolutely no rights whatsoever. The doctors and Mom are going to steer this ship and your just along for the ride. You are the passenger and helper. You’ll get ice and water, ask the nurse for small things and hold her hand. You’ll also get asked to leave now and then, you might get pushed to the side and you’ll get odd stares if you ask too many questions.