How to compress PNG image with S3TC/DXT algorithm in python?

时间:2019-04-08 13:24:17

标签: python opengl image-processing dxt

I try to find way for compressing images(PNG as an example) with any S3TC/DXT algorithm using python libraries.

As I can see in Pillow(PIL) library DDS format in Read-only formats section. Therefore Pillow can't be used for this purpose.
Searching in google didn't give positive results.

Question:

Is it possible to do with python?
Could someone please provide link to libraries with such functional?(which is checked on practice)
DDS format is not mandatory for my case. I need only compressed file.

PS:

It's required for creating textures for future use.
Library should support different algorithms of compression.

1 个答案:

答案 0 :(得分:2)

You could use Python Wand. Here I create a pseudo image with a magenta-yellow gradient and save as DDS:

from wand.image import Image
with Image(width=200, height=80, pseudo='gradient:magenta-yellow') as img: 
   img.save(filename='result.dds') 

enter image description here

Or, if you want to load a PNG file and save as DDS:

with Image(filename='input.png') as img: 
   img.save(filename='result.dds')