Domanda

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.

È stato utile?

Soluzione

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

Altri suggerimenti

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) 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top