Supporting Moblogging From The Nokia 7610

I’ve had to make some changes to my homebrew MMS moblog software now I have a Nokia 7610 phone.

The 7610 has a megapixel camera in it, which is far better than the very low res on in my old Nokia 7250.

The downside is I can’t use the images it creates directly in my blog as they are far to high resolution. What I needed to do was to reduce the size of the image coming in before posting it to the blog. I achieved this using the Image::Magick Perl module.

This snippet of code takes an image from a filename, resizes it to a maximum of 450 wide and 350 high, and saves it back out with the original filename.

my $oldimage = new Image::Magick;

The key to code is the use of geometry. Here I am saying what I would like the maximum boundries to be. Image::Magick does the rest, keeping the aspect ratio of the original image. The > at the end tells Image::Magick only to scale if the image is larger than that ratio, meaning smaller images are left untouched.

Great, so I have lovely scaled images. The next problem was that the software wasn’t picking up the attachment.

The Nokia 7250 attaches the image directly with the MIME type of image/jpeg, however the Nokia 7610 attaches it with the MIME type of application/octet stream. This means it’s hard to detect what the attachment is, however we are provided with a clue. We are given the recommended filename of the attachment, so scanning to see if it ends in .jpg lets us know if we have a JPEG image or not.

The code I use to detect the attachment in the octet-stream and put it into the variable $attachmentlooks something like this…

if ($entity->mime_type =~ m/application/octet-stream/i) {
if (($head->recommended_filename =~ /.jpg$/i) || ($head->mime_attr("") =~ /.jpg/i)) {
my $bh = $entity->bodyhandle;
my $attachment = $bh->as_string;

Where $entity is a MIME::Entity object and $head is a MIME::Head object from the entity.

I now have a tool that can take MMS email messages from various phones and post remotely to my blog.