How can I convert a .dds file to a .png in python?

Question:

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?

Asked By: faiuwle

||

Answers:

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.

Answered By: RUser4512

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')
Answered By: Yuriy Leonov
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.