Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-10367

Imagick support for thumbnailing very hi-res images on machines with PECL Imagick installed, exec/passthru/shell_exec disabled and with a low memory_limit.



      When uploading a very hi-resolution image on a restrictive machine, it will go for the GD approach.
      This however consumes a lot of memory and may give a blank page when hitting the PHP set memory_limit.
      A 5000x5000x24bit image would alone use ~75MB plus GD child process memory.
      So you would need to set the PHP memory_limit very high (on my site it had to be 128MB+) for each child process.

      Imagemagick resolves this by running "convert" as a shell command and thus having no PHP memory limits other than the limits of the machine.
      But restrictive machines (and recently Kloxo configs) made using Imagemagick impossible due to disabling these:


      Thus reverting to the GD path and failing on high resolution images.

      The resolution is to install/use the PECL Imagick (http://pecl.php.net/package/imagick) if possible and a little modification to the "/includes/functions_posting.php".
      This is basically a wrapper of Imagemagick that doesn't require (potentially unsafe) shell access through the passthrough command.
      "Imagick is a native php extension to create and modify images using the ImageMagick API." from http://pecl.php.net/package/imagick

      	// Only use imagemagick if defined and the passthru function not disabled
      	if ($config['img_imagick'] && function_exists('passthru'))
      		if (substr($config['img_imagick'], -1) !== '/')
      			$config['img_imagick'] .= '/';
      		@passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -quality 85 -geometry ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" "' . str_replace('\\', '/', $destination) . '"');
      		if (file_exists($destination))
      			$used_imagick = true;
      	else if (extension_loaded('Imagick')) {
      		try {
      			$imagickThumb = new Imagick();
      			$imagickThumb->resizeImage($new_width, $new_height, Imagick::FILTER_LANCZOS, 1, true);
      		} catch(Exception $e) {
      		if (file_exists($destination))
      			$used_imagick = true;
      	if (!$used_imagick)

      Just the else if portion.
      I ran into this problem when Kloxo forced disabling the shell commands on an update.
      (Which is perfectly fine for security)




            • Assignee:
              CHItA CHItA
              Ripper5555 Ripper5555 [X] (Inactive)
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: