Thumbnail creation for PNG Files fails

Hello,

i have another problem with my thumbnail creation. While displaying full size PNG Files works without a problem, thumbnail creation of them always fail.

I’m clueless where to look. Command Line ‘convert’ works without a problem. I’m using the ‘im’ thumbs driver.

c::set('thumbs.driver', 'im');	
c::set('thumbs.bin', '/usr/local/bin/convert');

Any idea where I should dive deeper?

Regards Alex

Do jpgs-thumbnails get created with the im driver?

Yes, they work without problems.

What is your environment?

Production environment:
Linux (Arch Linux), PHP 7.3, nginx, ImageMagick 7.0.8-21, libPNG 1.6.35

Same problem on my local dev environment:
OSX, PHP 7.3, nginx, ImageMagick, ImageMagick 7.0.8-21, libPNG 1.6.35

How much ram have you given PHP in the ini settings? PNGs usually take a little more horsepower to manipulate than JPEGS. Does this happen with all PNG files or just large ones in pixel dimensions and file size. have you tried a small one?

The php memory_limit is set to 512M. The thumbnail creation for really small pngs also fails.

What about the max_execution_time? But if it even fails for small pngs…, hm. Note that if the png is too small, thumbnails are not created, so the physical size should actually be bigger than the thumbnails size.

max_execution_time 30, but setting it to 180 does not solve the problem.

Does it also fail to make thumbnail if you use the imagemagick from the command line outside of Kirby? Its interesting that you have identical versions on both live and local and both fail. Im wondering if its a bug with that exact build of imagemagick.

@rcvd already said that is works from the command line.

Maybe I’m not using the same parameter as Kirby? Just tried a simple convert…

This is what the driver does, depending on settings:

/**
 * ImageMagick Driver
 */
thumb::$drivers['im'] = function($thumb) {

  $command = array();

  $command[] = isset($thumb->options['bin']) ? $thumb->options['bin'] : 'convert';
  $command[] = '"' . $thumb->source->root() . '"';
  $command[] = '-strip';

  if($thumb->options['interlace']) {
    $command[] = '-interlace line';
  }

  if($thumb->source->extension() === 'gif') {
    $command[] = '-coalesce';
  }

  if($thumb->options['grayscale']) {
    $command[] = '-colorspace gray';
  }

  if($thumb->options['autoOrient']) {
    $command[] = '-auto-orient';
  }

  $command[] = '-resize';

  if($thumb->options['crop']) {
    if(empty($thumb->options['height'])) {
      $thumb->options['height'] = $thumb->options['width'];
    }
    $command[] = $thumb->options['width'] . 'x' . $thumb->options['height'] . '^';
    $command[] = '-gravity Center -crop ' . $thumb->options['width'] . 'x' . $thumb->options['height'] . '+0+0';
  } else {
    $dimensions = clone $thumb->source->dimensions();
    $dimensions->fitWidthAndHeight($thumb->options['width'], $thumb->options['height'], $thumb->options['upscale']);
    $command[] = $dimensions->width() . 'x' . $dimensions->height() . '!';
  }

  $command[] = '-quality ' . $thumb->options['quality'];

  if($thumb->options['blur']) {
    $command[] = '-blur 0x' . $thumb->options['blurpx'];
  }

  $command[] = '-limit thread 1';
  $command[] = '"' . $thumb->destination->root . '"';

  exec(implode(' ', $command));

};

So if jpgs work, the driver seems to work ok, the php.ini settings seems to be ok as well.

I haven’t tested anything with PHP 7.3 yet…

convert input.png -strip -auto-orient -limit thread 1 -quality 90 -resize 400x400 -interlace line resized.png

This works without problems…

Can you see anything in the error logs?

I can’t see anything…but I’m not sure that my php logging is configured right…

I just noticed that libPNG is now at version 1.6.36 try updating it locally and see if the issue persists.

The problem seems to be caused by a configured png optimizer (pngquant / triggered by imagekit), if I remove this png starts working again. Sorry for the confusion…

Ah, didn‘t know you are using imagekit.

My fault…had to state this first.