Viewing posts tagged with snippet

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

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

Password Generator Bookmarklet

I created this little bookmarklet a few days ago to instantly create a random 10 character password. It's pretty handy as I'm always needing to create a new secure password.

If you need it more secure, you can edit the character list in the str variable, and edit the length of the password via the for loop. In this version, I've stripped out characters that look alike as it's annoying when can't tell exactly what the character is.

javascript: (function () {
    var tmp = '';
    var str = '23456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ';
    var len = str.length;
    for (var i = 0; i < 10; i++) {
        tmp += str[Math.floor(Math.random() * len)];
    }
    prompt('Your randomly generated password is:', tmp);
})()

To use it, simply drag the link below onto your browser toolbar, and then click it when you want to create a random password.

Generate Password

11-Apr-2011 at 4:06pm

Flickr and Youtube Bookmarklet

Here is a little bookmarklet I created to grab the short URL when viewing a video on YouTube or a photo on Flickr:

javascript: (function () {
    var a = location.host;
    if (a.indexOf('flickr') > 0) {
        var a = document.getElementsByTagName('html')[0].innerHTML;
        var b = a.match('http://flic.kr/p/([_a-zA-Z0-9]*)');
        if (b) prompt('The flic.kr URL is:', b[0]);
    }
    if (a.indexOf('youtube') > 0) {
        var a = document.getElementsByTagName('link');
        for (var i in a) {
            var b = a[i];
            if (b.getAttribute('rel') == 'shortlink') prompt('The youtu.be URL is:', b.getAttribute('href'));
        }
    }
})()

To use it, simply drag the link below onto your browser toolbar, and then click it when viewing a video or photo.

Grab Short URL

05-Apr-2011 at 3:17pm