Making thumbnails with Perl

With the help of ImageMagick you can automagically use Perl to create thumbnails. The example below is quite rude and makes a 50 by 50 thumbnail (no matter which size and shape the master had). Before using it in a real world scenario, check the aspect ratio, the size of the original image and what ever may be applicable.

#!/usr/bin/perl -w
use strict;
use Image::Magick;

my $image = Image::Magick->new(magick=>'JPEG');
my $x = $image->Read('test.jpg');

$x = $image->Scale(width=>'50', height=> '50');

# The following should also work fine...
# $x = $image->Scale(geometry=> '50x50');

$x = $image->Write('test.50x50.jpg');

exit();

Rotating an Image with Perl

Turning images is quite simple. In the example below an image is turned 90 degrees clockwise, wirtten to a file, turned another 90 degress and written to a file again.

#!/usr/bin/perl -w
use strict;
use Image::Magick;

my $image = Image::Magick->new(magick=>'JPEG');
my $x = $image->Read('test.jpg');

$x = $image->Rotate(degrees=>90); # 90 degress clockwise
$x = $image->Write('test.90.jpg');

$x = $image->Rotate(degrees=>90); # Another 90 degress clockwise
$x = $image->Write('test.180.jpg');

exit();

Google and the iPhone

Appleinsider has an interesting little story. It reports how the iPhone usage shocks Google

  • being far above the expectations. I don’t have any expectations, have so far not used nor touched an iPhone, but frankly you shouldn’t be too surprised.

Sure I’ll probably get blamed as an Apple fanboy, but I hardly know any other company who is able to - so successfully - match the possibilities of technology with consumer desires.

PHP Coding Standards

If you’re part of a larger team developing (and sharing) code, it is a pretty good idea to have some common standards. In the PHP work, such a set of common standards include the PEAR Coding Standards. While it may be a challenge to agree on standards, it can be done - the hard part is following the standards.

One excellent tool to help you check for standards compliance is the PHP CodeSniffer. We’ve had it running for quite awhile and it seems to work as advertised. We’ve made our own (“TDC”) coding standards which is a variation over the PEAR coding standards, and checking if you follow them is as simple as running a simple command line. While it doesn’t enforce following of the coding standards, it does make it a no-brainer to check if you do follow the common standards.

Database optimization thoughts

If you’re working on heavy duty websites, knowing your database and how to use it best can make a world of difference in terms of performance, and thus you should always optimize the database. That’s pretty much obvious.

The tricky part is how you do the optimization? Often it requires a lot of reading up on how the database works - strengths, weaknesses and other details — and loads of experience. Having a DBA available to help you optimize would be ideal in some cases, but often you need to do it yourself.

Substring magic with mysql

Mysql is a wonderful database, and while many use it, most people only scratch the surface of what the database can do. One of the practical functions available is the substring_index function, and an imaginary mailing list example is a nice way to show how to use it.

Let imagine we have a mailinglist in a table named “mailinglist” and it has a (char) column with the email addresses subscribed to the list. We now want to figure out how many users, that are subscribed from the various domains in the list.

MacBook Air - fair criticism?

Earlier this week Apple introduced a new line in their laptop lineup - the MacBook Air. On the web there’s been a number of people criticizing the MacBook Air, and frankly I really don’t get why they need to have every Apple product be a perfect match for them - they aren’t and they’re not supposed to be.

“Top 10 Flaws of the Macbook Air”

Let me add a few comments to some of the points on one of the lists criticizing the Macbook Air:

Footers - not just the end of the page

On most websites - including this one - the footer is the boring place where you (usually) place all the pocket lint, which didn’t make it into the page anywhere else. It usually have a copyright notice, links to a site map and other stuff which may be important, but not interesting (speaking in very broad terms).

Today I came across an article on footers with great usability. Footer Usability? Yes, and from a blunt disregard and ignorance, I’ve discovered that the site footer is an excellent place to place a lot more effort.

Quality of code

Not  all code are created equal. Some pieces of code are more important than others. The code that powers critical parts of a nuclear power plant is hopefully of a much higher standard than the code behind this site, but how do you recognize which quality of code you should aim for when developing websites?

A website may not have one set level for all content - usually the various pieces which make up the site (no matter if it be classes, files or functions - in PHP). On the level you’re looking, let me suggest, for each piece you judge the required (minimum) quality on two simple parameters: