I Love Open Source

by @edent | # # #

As I mentioned in my last post about VoteUK, I found the TheyWorkForYou API to be a little lacking when it came to image sizing.

I posted a request asking if there was a pattern to the image sizes and, if not, was it possible to have the sizes returned in the API.

The “standard” open source reply – “fix it yerself” – was predictably swift.

So I did.

The source code is remarkably accessible – although a few more comments wouldn’t go amiss.  This was my first experience with GIT and Github.  It was easy to get the code and, luckily, I didn’t have to dive too far in to its syntax.

I had initially thought about using the EXIF data within the images to get the width and height.  Unfortunately, not every image can be guaranteed to have (accurate) EXIF data.  PHP to the rescue once again with the getimagesize() function.

So, where we previously had

if ($image) $row['image'] = $image;

This becomes

if ($image) {
	list($width, $height) = getimagesize($image);
	$row['image'] = $image;
	$row['image_height'] = $height;
	$row['image_width'] = $width;

Many thanks to Matthew Somerville for testing and releasing the patch in double quick time. You can examine the changes made to the code.

So now the API returns,



So, I have a problem, I can see how much effort it will be to fix, I suggest a solution, it works and goes into production.  That’s the awesome power of open source.

Leave a Reply

Your email address will not be published. Required fields are marked *