Reputation: 93
I tried converting PSD to PNG, but as I save the PNG, Wand (wand-0.4.0-py2.7) spits out all layers inside the PSD as separate PNG files (the last file saved is the one I want). So how to correctly convert from PSD to PNG?
# Convert a large PSD to small PNG thumbnail
myImage = Image(filename="test.psd")
myImage.resize(100, 100)
myImage.format = "png"
myImage.save(filename="test.png")
found related solution:
but not sure how it can be done in Python (I'm new to Python)
Any help is appreciated.
Upvotes: 2
Views: 5880
Reputation: 93
This would work just well and fast for both read and write:
# Convert a large PSD to small PNG thumbnail
myImage = Image(filename="test.psd[0]")
myImage.format = "png"
myImage.sample(100, 100)
myImage.save(filename="test.png")
Because Wand is only reading 1 layer instead of all the layers inside the PSD.
For more complicated operations with PSD files, you may consider Python psd-tools (https://pypi.python.org/pypi/psd-tools). but from my initial testing, it reads PSD rather slow (maybe because it reads the entire PSD).
It'd be useful if you want to load PSD (or other image formats) into Qt UI. The concept is to convert image loaded by Wand into image string, and send that image string to QImage.
# load the image first
myImage = Image(filename=r"c:\test.psd[0]")
myImage.format = "png"
myImage.sample(100, 100)
aBlob = myImage.make_blob()
# load the image data into QImage
myQImage = QtGui.QImage.fromData( aBlob )
myQPixmap = QtGui.QPixmap.fromImage( myQImage )
target_QLabel.setPixmap( myQPixmap )
Upvotes: 2