Created
June 8, 2011 03:25
-
-
Save PyYoshi/1013712 to your computer and use it in GitHub Desktop.
python-webmで実際に変換してみる。PIL、python-webmそれとlibwebp.soが必要。いまのところpython-webmはWinには対応してない。 ちょっといじればできそうだけども^^;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from webm.encode import WebPEncoder | |
from webm.handlers import BitmapHandler | |
import Image | |
import os | |
# 初期値 | |
IMAGE_WIDTH = 1200 | |
IMAGE_HEIGHT = 1600 | |
fpath = os.path.join( os.path.dirname( __file__ ), "test.jpg" ) | |
# ここにImageを使用。Imageでいろいろいじったあと最終的に以下の行の処理を行えば問題ないとおもう | |
im = BitmapHandler(bytearray(Image.open(fpath).tostring() ), | |
BitmapHandler.RGB, | |
IMAGE_WIDTH, | |
IMAGE_HEIGHT, | |
IMAGE_WIDTH * 3) | |
encoder = WebPEncoder() | |
webp_obj = encoder.encodeRGB(im) | |
webp_file = open(os.path.join( os.path.dirname( __file__ ), "test.webp" ), 'wb') | |
webp_file.write(webp_obj.data) | |
webp_file.close() | |
# パフォーマンス微妙。 リサイズとかしなければconvertとか付属のcwebp、dwebp使ったほうがいいと思うよ。 | |
# それとwebp自体まだ開発中でライブラリが突然使えなくなることあるからアレ。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment