I Love Open Source


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,

/images/mps/10409.jpg
59
49

Brilliant!

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.


Share this post on…

  • Mastodon
  • Facebook
  • LinkedIn
  • BlueSky
  • Threads
  • Reddit
  • HackerNews
  • Lobsters
  • WhatsApp
  • Telegram

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <p> <pre> <br> <img src="" alt="" title="" srcset="">