2

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.

Yuriy Leonov
  • 536
  • 1
  • 9
  • 33

1 Answers1

3

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') 
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • It's just saving in other extention. I've looked at `Wand` and didn't find ability to chose compress algorithm: like DXT1-5, etc. https://www.khronos.org/opengl/wiki/Image_Format#Compressed_formats – Yuriy Leonov Apr 08 '19 at 14:16
  • If I use the above code and save as TIFF, I can add in an extra line before `img.save()` that sets `img.compression='lzw'` or `img.compression='zip'` and it honours that. If I set `img.compression='dxt5'` it does not honour it... maybe Eric will know @emcconville – Mark Setchell Apr 08 '19 at 14:43
  • yeap, http://docs.wand-py.org/en/0.5.2/wand/image.html?highlight=compression it's really supported, and looks like even can save in dds format with compression. BTW, offtop: .dds files could be used in personal projects? I mean is it legal format? :) (I know it could sound stupid) – Yuriy Leonov Apr 08 '19 at 15:13