MT::Image - Movable Type image manipulation routines


    use MT::Image;
    my $img = MT::Image->new( Filename => '/path/to/image.jpg' );
    my($blob, $w, $h) = $img->scale( Width => 100 );

    open FH, ">thumb.jpg" or die $!;
    binmode FH;
    print FH $blob;
    close FH;


MT::Image contains image manipulation routines using either the NetPBM tools or the ImageMagick and Image::Magick Perl module. The backend framework used (NetPBM or ImageMagick) depends on the value of the ImageDriver setting in the mt.cfg file (or, correspondingly, set on an instance of the MT::ConfigMgr class).

Currently all this is used for is to create thumbnails from uploaded images.



Constructs a new MT::Image object. Returns the new object on success; on error, returns undef, and the error message is in MT::Image->errstr.

%arg can contain:

  • Filename

    The path to an image to load.

  • Data

    The actual contents of an image, already loaded from a file, a database, etc.

  • Type

    The image format of the data in Data. This should be either JPG or GIF.


Creates a thumbnail from the image represented by $img; on success, returns a list containing the binary contents of the thumbnail image, the width of the scaled image, and the height of the scaled image. On error, returns undef, and the error message is in $img->errstr.

%arg can contain:

  • Width
  • Height

    The width and height of the final image, respectively. If you provide only one of these arguments, the other dimension will be scaled appropriately. If you provide neither, the image will be scaled to 100% of the original (that is, the same size). If you provide both, the image will likely look rather distorted.

  • Scale

    To be used instead of Width and Height; the value should be a percentage (ie 100 to return the original image without resizing) by which both the width and height will be scaled equally.


This utility method returns a width and height value pair after applying the given arguments. Valid arguments are the same as the scale method. If 'Width' is given, a proportionate height will be calculated. If a 'Height' is given, the width will be calculated. If 'Scale' is given the height and width will be calculated based on that scale (a value between 1 to 100).


Please see the MT manpage for author, copyright, and license information.