PHP/Imagick/PDFlib Flop Image Changes its Bit Depth

情到浓时终转凉″ 提交于 2019-11-29 08:41:56

Imagick is using the smallest format possible to save the image. Saving in these formats all produce the same image but have the sizes:

  • Palette - 3.38kB
  • RGBA 32bit - 6.14kB
  • RGBA 64bit - 8.09kB

Saving to the smallest possible file is usually what people desire. However you can disable this in a couple of ways.

You can tell Imagick to use the same PNG format as the source image by setting the png:format option to png00. e.g.

$imagick = new Imagick(realpath("../images/FlopOriginal.png"));
$imagick->flopImage();
$imagick->setOption('png:format', 'png00');
$imagick->writeImage("../images/Flop.png");

The full options for png:format are png8, png24, png32, png48, png64, and png00.

Alternatively you can explicitly set the image format to use when saving the PNG file, through the png:bit-depth and png:color-type e.g.

$imagick = new Imagick(realpath("../images/FlopOriginal.png"));
$imagick->flopImage();
$imagick->setOption('png:bit-depth', '8');
$imagick->setOption('png:color-type', 6);
$imagick->writeImage("../images/Flop.png");

The color type values come from the libpng.h and are:

PNG_COLOR_TYPE_GRAY         0
PNG_COLOR_TYPE_RGB          2
PNG_COLOR_TYPE_PALETTE      3
PNG_COLOR_TYPE_GRAY_ALPHA   4
PNG_COLOR_TYPE_RGB_ALPHA    6

Both those methods produce a flopped image that is RGBA 32bit like the original image.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!