Blog

  • PHP image thumbnails

    I mentioned in a post yesterday that I also use PHP to generate image thumbnails. The idea is that any new photos I simply upload to the BMTG site, with a Picasa caption attached, and the site should do the rest.

    Thumbnails are generated on-the-fly but only once as, once created, they are saved and re-used.

    if (!file_exists($thumb_filename)) {
    
       $src_img=imagecreatefromjpeg($full_filename);
       $old_x=imageSX($src_img);
       $old_y=imageSY($src_img);
    
       $new_w=round(($old_x/$old_y)*100);
       $new_h=100;
    
       $dst_img=ImageCreateTrueColor($new_w,$new_h);
       imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,$old_x,$old_y);
       imagejpeg($dst_img,$thumb_filename);
       imagedestroy($dst_img);
       imagedestroy($src_img);
    }

    $thumb_filename should contain the filename of the thumbnail and $full_filename is the filename of the original image (that the thumbnail is taken from). In the case of this example I’m creating thumbnails that have a height of 100 pixels and maintain their ratio, hence the width is variable.

    The above can be made a lot more compact, but I’ve expanded it out to make it easier to follow.

    By the time the code has finished, if the thumbnail didn’t already exist, it now does. Make sure the folder that the thumbnails are stored in has the appropriate permissions though!

  • Router fixed!

    My earlier issues with my router have been fixed! But I’m not quite sure what it was.

    Last night, after having done some research on the ‘net, I decided to try and sort the problem out. First of all I removed the WEP security (yes, WEP) and tried the Wii… still not connecting. So I turned WEP back on, but at the same time turned the wireless off and on again. I then changed the channel to 11 (there are other people nearby on this channel but I know the Wii is supposed to connect quicker on this particular channel).

    I then tried the Wii again… success. And the SoundBridge came on too.

    Ok, so it sounds like there was interference on the channel I was on. Except, according to NetStumbler, nobody was and I was getting a clear frequency before. I think when I got my new router I set it to channel 3, but having looked at my past post on changing channels I think I was on 4. Now that might explain why the problems have only started since I got the new router, but I don’t understand what the channel issue was.

    Oh well, NetStumbler shows channel 11 to be coming in loud and incredibly clear and all now appears well. But still, all a bit strange.

  • Reading Picasa captions in PHP

    Ok, it’s going to get technical.

    Although I’ve recently bought Photoshop Elements, Picasa used to be my photo browser of choice (in fact it still is as I get used to Photoshop). Therefore when I wanted an easier way to add photos to the BMTG website, I developed it with Picasa in mind.

    Apart from the site generating its own thumbnails, it also gets its description from the embedded Picasa data. I found out the data after reading on the PHP site about looking at EXIF and other image data and writing a program to display it all – this revealed the Picasa caption field.

    However, it did seem to have an anomaly in that it ended with a null character. I therefore coded around this. Unfortunately (depending how you look at it) with Picasa 3, this appears to have been fixed and so recently described photos are being truncated on my site. It’s not too much of a hassle, though, to detect for this. The code I use is as follows…

    list($width, $height) = getimagesize($full_filename, $info);
    $iptc = iptcparse($info["APP13"]);
    $description = $iptc["2#120"][0];
    if (ord(substr($description,-1))==0) {
       $description=substr($description,0,-1);
    }

    Simply populate $full_filename with, well, the filename of the image. At the end of it all the Picasa caption will be in $description and the image width and height in $width and $height.

    The last line of the code is where I’m working around the null character at the end of the caption (or not).

  • Speed up your broadband

    There are lots of useful hints and tips around – often relating to fiddling around with your MTU, for instance – few of which I’ve found give any benefit. However, here’s one that even gets the backing of BT.

    It would appear that in many people’s master BT socket (the one that all your other extension cables and phones are plugged into) there is a wire still in use that, well, isn’t really needed – the bell wire. And it can often cause interference resulting in slower internet connections.

    The DIY answer is to open up this socket and remove the wire. The safer option for those who are terrified of pulling on a limp cable that’s barely held in place by anything, is to buy the iPlate from BT. Yes, BT have created a replacement front for your master box that essentially does this for you. And for less than £6 (inc P&P).

    Zen Internet, my ISP, have been quotes as saying…

    In a small scale trial we performed… the results [were] varied from no increase up to 1Mb/sec

    You may not see immediate improvements because BT automatically limits the speed of your line to match your sync speed to improve connection stability. This is known as your BRAS profile (Zen Internet have an excellent support site for customers where you can check your current BRAS profile) and it can take up to three days for BTs automated equipment to adjust this profile.

    Personally, I was disappointed – not by the results but the fact that the wire was already missing from mine when I checked, so I have nothing to try. Drat.

  • Hear of this rumour!

    Super Smash Bros. Brawl is a great game. And its title music is superb too – especially the choral singing.

    Anyway, it turns out that the singing is Japanese translated into Latin. However, translating roughly back to English it is…

    Hear of this rumour!
    (He) Alone rushed against enemies.
    And saved the fatherland.
    Hear of this rumour!
    Hear of this rumour!
    Hope to all, also to me,
    Terror to all, also to me,
    That one (is) near to me,
    That one (is) near to me,
    Who at that time were strong men
    And rivals.
    Ferociously, struggling and fighting
    Splendour growing.

    Doesn’t really go with the cuddly Nintendo image 😉