Search code examples
pythonnumpywand

how to convert a numpy array into a wand.image.Image object?


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?


Solution

  • 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)