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

Viewed 320

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?

2 Answers

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)

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

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