Question

I have blob representing webp image I want to be able to create an image from the blob using Wand and then convert it to jpeg. Is that possible with Wand or any other python library.

Was it helpful?

Solution

Wand is a wrapper for imagemagick - in general, the file types that Wand supports are based on how imagemagick is configured on the system in question.

For example, if you're on a mac using homebrew, it would need to be installed with:

brew install imagemagick --with-webp

OTHER TIPS

Well I could not do it with Wand. I found another library Pillow.

I have a java script code that capture video frame from canvas and convert the webp imge from based64 to binary image and send it using web socket to a server on the server I construct the image and convert it from webp to jpeg and then use OpenCV to process the jpeg image. Here is a sample code

from PIL import Image
import StringIO
import numpy as np
import cv2

#webpimg is binary webp image received from the websocket 
newImg = Image.open(StringIO.StringIO(webpimg)).convert("")
temp = StringIO.StringIO()
newImg.save(temp, "JPEG")
contents = temp.getvalue()
temp.close()

array = np.fromstring(contents, dtype=np.uint8)
jpegimg = cv2.imdecode(array, cv2.CV_LOAD_IMAGE_COLOR)
cv2.imwrite("imgCV.jpeg", img1) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top