3

I want to save a numpy array as a .dds file, here is how i got the array:

import numpy as np
from wand import image

with image.Image(filename='test.dds') as dds:
    arr = np.array(dds)

after i got the array, i need to save it as another .dds file using the following codes:

dds.compression = 'dxt5'
dds.save(filename='test2.dds')

but it seems that dds must be a wand.image.Image object, so my question is, how can i convert the numpy array to a wand.image.Image object?

xiaojifeng
  • 45
  • 3

2 Answers2

4

I think you want the class method Image.from_array:

from wand.image import Image

# Make wand Image from Numpy array
wi = Image.from_array(numpyArray)
jneuendorf
  • 402
  • 6
  • 18
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
0

You are looking for wand.image.Image.from_array:

ndds = dds.from_array(arr)
ndds.compression = 'dxt5'
ndds.save('test2.dds')