简体   繁体   English

魔杖支持读/写webp图像吗?

[英]does wand support reading/writing webp images?

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. 我有blob代表webp图像我希望能够使用Wand从blob创建图像,然后将其转换为jpeg。 Is that possible with Wand or any other python library. 这可能与Wand或任何其他python库。

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. Wand是imagemagick的包装器 - 通常,Wand支持的文件类型基于如何在相关系统上配置imagemagick。

For example, if you're on a mac using homebrew, it would need to be installed with: 例如,如果您使用自制软件在Mac上,则需要安装:

brew install imagemagick --with-webp

Well I could not do it with Wand. 好吧,我无法用魔杖做到这一点。 I found another library Pillow . 我找到了另一个图书馆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. 我有一个java脚本代码从canvas获取视频帧并将webp imge从based64转换为二进制image并使用web socket将其发送到服务器上的服务器我构建映像并将其从webp转换为jpeg然后使用OpenCV处理jpeg图像。 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) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM