Movable Type Nikon Jpeg Image Upload Issue

| No Comments | No TrackBacks |
Recently I ran into an obscure issue with image uploads on a Movable Type installation of one of my clients.  Several users had been complaining about photos being uploaded into the entry editor not showing up as (thumbnailed) images, but as direct download links.  When later trying to insert the same image in a different entry, the image would ony show up as a file, not as a (thumbnailable) image.  All these images appeared to have been taken with recent Nikon-brand cameras.
I tested uploading the image on MT4 and on MT5, and in both cases went to check out the listing for it in the asset manager ("Manage > Assets" under MT4, "Assets > Manage" under MT5).  When clicking the item in question, it revealed that the file has been saved as an 'Asset' instead of an 'Image' (which is what it should normally have been for an image file).

Some digging in MT's code turned up that during the upload process a check was being made on the file to determine the dimensions, and that this check was failing.  For this reason, Movable Type then decided that the file wasn't a real image and just treated it like an unknown file.

The check was made in the lib/MT/Image.pm file (both in MT4 and MT5) and it involved trying to find out the image dimensions by using the Image::Size perl module (which comes pre-loaded with Movable Type).  For this particular image, this module was returning the error message "JPEG marker not found".  Even when upgrading Image::Size to the most recent version the error remained.

I was able to come up with a solution though.  I noticed that I could manipulate the image using imagemagick on my server's command line.  So obviously imagemagick was able to read the file.  Since imagemagick is also capable of determining the height and width of an image, and I had the Image::Magick perl module already installed on my server anyway, I tried the following.

In lib/MT/Image.pm there is a line that reads:

    my ( $w, $h, $id ) = Image::Size::imgsize($fh);

Directly below this line I inserted following code:

    unless ($w + $h){
            require Image::Magick;
            seek($fh, 0, 0);
            my $image = Image::Magick->new;
            $image->Read(file=>$fh);
            $h = $image->Get('height');
            $w = $image->Get('width');  
            $id = "";
            seek($fh, 0, 0);
    }

What this does is simply check for height and width using the Image::Magick perl module if they are returned as zero or none existent by Image::Size.  For some reason Image::Magick didn't have any problem with the images in question.  Of course, this does require that you have both imagemagick and Image::Magick on your server.

I also reported the issue to Six Apart, obviously.

No TrackBacks

TrackBack URL: https://www.movabletips.com/cgi-bin/mt/mt-tb.cgi/2592

Leave a comment