Viewing posts tagged with php

Xbox API Twitter Bot

Alan Wynn, who built and maintains the Unofficial Xbox API, gave me full access to his Twitter bot over the weekend after I suggested some improvements to the service.

In its original form you would send a Tweet to the bot in a certain format and it would look up the specified gamertag and reply to the tweet with their current online or offline status.

Xbox API Bot

My suggestion was that if the user is offline then it would continue to check the online status every minute and tweet when the gamer eventually came online. After a complete rebuild, and taking into account multiple requests for a single gamertag, having a 7 day limit to the checks and XboxAPI limit checks, it was complete.

Usage is really simple, just Tweet the following but be sure to replace 'Major Nelson' with any gamertag of your choosing. If it doesn't exist, you'll be notified by a Tweet.

@XboxAPI_Bot isonline Major Nelson

You can fork the code on Github or send a Tweet to see it working in action.

29-Sep-2013 at 5:59pm

Minecraft Skin Preview via PHP

I've expanded on my Minecraft Avatar script I built a while back so that you can now display a skin preview for a given username, like so:

Minecraft Skin Preview

It's as easy as this to use:

<img src='skin.php?u={username}&s={size}' />

Just like the facial avatar, this script grabs their skin from the Minecraft server, and then creates the 4 different views, including facial accessories such as hats or glasses. If the username does not exist, then it uses the default skin, which is stored in a base64 encoded variable to save an extra cURL request.

Check out the code on Github

PHP Blink(1) Class

I've been playing around and having quite a bit of fun with my Blink(1) by ThingM for some time now, and whilst the command line tool is very good, it's somewhat fiddly to send patterns. As a result, I build my own PHP class to interact with the CLI tool.

The example below simply fades to #F68 for 400ms, then fades to #0F1 for 400ms, and then fades to #F68 for 400ms, and this loops 3 times:

Blink::send('#F68,400|#0F1,400|#F68,400',3);

You can even go a step further an introduce a flicker effect by adding a quick fade to #000 between each light like so:

Blink::send('#F68,400|#000,50|#ff8920,400|#000,50|#F00,400',3);

The video below demonstrates all the examples as per example.php in the Github Repo

You can view the video on Vimeo or fork the code on Github.

26-Jul-2013 at 12:46pm

Thumbnail Creation via PHP

I got a bit tired of numerous security holes and sheer bulkiness of other thumbnail generation scripts, so decided to build my own from scratch, for local images only. Simply upload, create a writable cache directory and parse the image through the PHP script like so:

<img src='thumb.php?src=./images/photo.jpg&size=400x300' />

It's super simple and only 155 lines in total. You can specify the width and height, or just the width so the height will get calculated automatically and vice versa. It also allows you to set a maximum width/height, which is best suited for photo thumbnails.

Features:

  • File based cache
  • Automatic deletion of expired cache files
  • Optional browser based cache via the IF_MODIFIED_SINCE HTTP header
  • Multiple size types
  • Options whether to crop, trim, zoom and set alignment
  • Set sharpness based on a percentage midpoint between two values, so you can specify the strength of the sharpness rather than just turning it on or off

Check out the code and usage instructions on Github

Minecraft Avatar via PHP

Here's a little something I built for fun a while back, when I was more active on Minecraft. I wanted a real simple way to generate a user's Minecraft avatar from their skin, and be able to display at any size.

Minecraft Avatar

It's as easy as this to use:

<img src='face.php?u={username}&s={size}' />

What the script does is grabs their skin from the Minecraft server, copies the face and facial accessories only and merges them into an 8 x 8 image, then resizes to the specified size. If the username does not exist, then it uses the default skin, which is stored in a base64 encoded variable to save an extra cURL request.

Check out the code on Github