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?
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.
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')
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?
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.
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')