Forum: Poser Python Scripting


Subject: How to call ImageMagick from PoserPython

HartyBart opened this issue on Aug 03, 2021 ยท 23 posts


HartyBart posted Sun, 08 August 2021 at 5:18 PM

After a little digging I now see that a Pillow (PIL) optimize command is available for PNG, at least according the Handbook. A simple convert using optimize then works when run from Poser 11:

import poser
from PIL import Image

im = Image.open(r"C:|Users|NAME|input.png")

im.save(r"C:|Users|NAME|output.png",optimize=True)

However, with optimize=True set, the output file is actually slightly larger. Which is obviously no use.

The user might also add a line between these to quantize the PNG to shrink it - by reducing the palette size. There appear to be two ways to do this, old and new:

im = im.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=256)

or

im = im.quantize(method=2)

But both fail under Poser 11. Either "quantize is not found", or the PNG "has the wrong mode". There appears to be no way to "import qualitize", at least under Python 2.7, which I thought might be something that was needed. Either method - when it works - apparently has major problems with maintaining background transparency, though there appear to be highly complex pixel sampling workarounds for this.

So the idea of using PIL (to bypass having to call an EXE file via subprocess.call) does not appear viable for automatically optimizing Poser 11's PNG image output.



Learn the Secrets of Poser 11 and Line-art Filters.