pythonpython-3.ximagemagickwanddds-format

How to avoid creating mipmaps for dds using python Wand?


Env:

python - 3.6.6
Wand - 0.5.7

Code example:

Part of this file

from wand import image

with image.Image(filename='example_32_on_32_px.png') as img:
    img.compression = 'dxt3'
    img.save(filename='output.dds')

It will produce output.dds which contains 5 mipmaps (16px, 8px, 4px, 2px, 1px).

I found CLI example for ImageMagic how to disable creation of mipmaps for output dds files -> this answer
But I need to do same using python and Wand.

Question:

How to prevent / avoid / disable / delete mipmaps in output file using Wand library and python.


Solution

  • You would use Image.options dict to set the property.

    from wand.image import Image
    
    with Image(filename='example_32_on_32_px.png') as img:
        img.options['dds:mipmaps'] = '0'
        img.compression = 'dxt3'
        img.save(filename='output.dds')