2

I am trying to create some images by manipulating image pieces stored in .dds files, and then write the finished image as a .png. I see that there is a dds python module in Direct Python 11, which seems possibly sufficient except that it saves to .dds format. Is there a way to save to another image format?

Reinier Torenbeek
  • 16,669
  • 7
  • 46
  • 69
faiuwle
  • 359
  • 1
  • 3
  • 10

2 Answers2

4

The Python Imaging Library has a open() method that supports dds files and has a read and save() can save an image to many formats (png included).

Note that, at the moment, only DXT1, DXT3, and DXT5 pixel formats are supported and only in RGBA mode.

RUser4512
  • 1,050
  • 9
  • 23
3

Since Python Imaging Library link is not available, I will show a solution with the wand library:

from wand import image
with image.Image(filename="white_rect_dxt3.dds") as img:
    img.compression = "no"
    img.save(filename="white_rect_dxt3.png")

And same from .png to .dds

from wand import image
with image.Image(filename='white_rect.png') as img:
    img.compression = "dxt3"
    img.save(filename='white_rect_dxt3.dds')
Max S.
  • 3,704
  • 2
  • 13
  • 34
Yuriy Leonov
  • 536
  • 1
  • 9
  • 33
  • Couldn't get it to work with Pillow, but wand worked like a charm! – Max S. Jun 01 '21 at 15:25
  • Here is an updated link: https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html – Hexiro Apr 23 '22 at 01:05
  • getting error: ImportError: MagickWand shared library not found. Trying installing: pip install ImageMagick But that also not working, ERROR: No matching distribution found for ImageMagick Is it not a Python module? – imankalyan Jun 22 '23 at 06:03