Pre-processing huge pictures with ImageMagick

See also Cookbook:SystemLimits about how to increase the time and memory limitations of your system.

When your users upload a huge picture, processing it with Mini may hit the PHP memory limits. Additionnally, pictures larger than the screen of the visitor often look bad. One possible workaround is to resize down the picture with ImageMagick before converting it with Mini.

This can be done automatically, from Mini version 20100210 or newer, and if you have the mogrify program, part of ImageMagick, installed and working on the server. It might not work in "safe_mode".
To install it, add to local/config.php the following code:

  function uMiniCreateMax($fpath,$mpath,$W,$H,$T,$idx) {
    $maxW = 1000;
    $maxH = 750;
    global $Now;
    if( $W>$maxW || $H>$maxH) {
      @copy($fpath, "$fpath,$Now");
      exec("mogrify -resize \"{$maxW}x{$maxH}>\" -quality 90 \"$fpath\"");
      clearstatcache();
      list($W, $H) = @getimagesize($fpath);
    }
    return MiniCreate($fpath,$mpath,$W,$H,$T,$idx);
  }
  $Mini['CreateFunction'] = 'uMiniCreateMax';

You can configure the lines starting with $maxW and $maxH : a maximum width and height in pixels of the pictures. If a picture is bigger than these values, it will be resized down to fit in them. The original picture will be renamed and will look like a "deleted" file in the upload directory.

Enjoy.

See also: Orientation.