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 | |
fpath = os.path.join( os.path.dirname( __file__ ), "test.jpg" ) | |
im = Image.open(fpath) | |
""" | |
ここにImageでいろんな処理追加ー | |
""" | |
IMAGE_WIDTH,IMAGE_HEIGHT = im.size | |
pre_webp = BitmapHandler(bytearray(im.tostring() ), | |
BitmapHandler.RGB, | |
IMAGE_WIDTH, | |
IMAGE_HEIGHT, | |
IMAGE_WIDTH * 3) | |
encoder = WebPEncoder() | |
webp_obj = encoder.encodeRGB(pre_webp) | |
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