1

I'm assembling a bunch of .tif using Imagick. Everything is going good, except that the color depth of the output image is always reduced (16 on the input, 1 on the output). I'm using setImageDepth() during the process, but it looks like it has no effect at all. Here's a snippet:

$imagick = new Imagick();
foreach ($_pile_of_tiles as $_index_to_append) {
    $_tmp_buffer = new Imagick();
    $_tmp_buffer->readImage($_index_to_append . ".tif");
    $_imagick->addImage($_tmp_buffer);
}
$_imagick->resetIterator();
$_appended_images = $_imagick->appendImages(true);
$_appended_images->setImageFormat("tiff");
$_appended_images->setImageDepth(16);
file_put_contents("output.tif", $_appended_images);

That gives me a 1-bit image. I tried doing this using the command-line, and it works fine (-depth 16).

Does someone encountered a similar issue?

aspretto
  • 117
  • 3
  • 9
  • this may help: http://stackoverflow.com/questions/19585032/php-imagick-pdflib-flop-image-changes-its-bit-depth – brandelizer Dec 11 '15 at 10:41
  • @brandelizer Thank you, but not really. I know Imagick tries to save the output at the smallest possible size, but it is still supposed to interpret my `setImageDepth()`. – aspretto Dec 11 '15 at 11:01
  • yeah....it's entirely possible that it's setting the image depth to 16 and then when it's 'writing' the files by converting it to a string, it's reducing it back to 1bit. Please can you try doing the stuff suggested in the other answer. – Danack Dec 11 '15 at 13:52
  • That's exactly what I'm trying to figure out; why is it ignoring the depth I specify, when writing the file? And concerning your other post, the option `bit-depth` does not apply to `.tif`, right? Also, I tried to keep the same color space, but it doesn't change a thing. – aspretto Dec 11 '15 at 14:07

1 Answers1

3

After looking at the code for the underlying ImageMagick library, apparently this works:

$imagick = new Imagick();
$imagick->newPseudoImage(200, 200, 'xc:white');
$imagick->setType(\Imagick::IMGTYPE_TRUECOLOR);
$imagick->setImageFormat('tiff');
$imagick->setImageDepth(16);
$imagick->writeImage("./output.tif"); 

system("identify output.tif");

Output is:

output.tif TIFF 200x200 200x200+0+0 16-bit sRGB 241KB 0.000u 0:00.000

No. That's not documented anywhere in the ImageMagick docs. Woo.

Danack
  • 24,939
  • 16
  • 90
  • 122