Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

numpy

wand

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?

like image 846
xiaojifeng Avatar asked Feb 19 '26 15:02

xiaojifeng


1 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)
like image 110
Mark Setchell Avatar answered Feb 22 '26 14:02

Mark Setchell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!