TclMagickはGraphicsMagick(以下GM)寄りで、ImageMagick(以下IM)も
サポートしているというのは嘘ではないのだが、GMのバージョンアップが
遅れているせいなのか(遅れてるのかどうか知らないが)何なのか知らないが、
とにかくいつまでたってもGMがIMのwand APIの重要なAPIを
取り込んでくれないので、仕方が無いので自分でパッチを書いた。
IMにあってGMには無い機能は、他にもたくさんあると思うのだが、
その辺をどうするのかポリシーがよくわからないし、作者の方に聞くのも
めんどくさいし、結局GMに存在しないwand APIはIM互換の自作APIで代用し、
GMでもIMどちらでも、IMのAPIのTclラッパーを使えるようにした。ただし
IM用とGM用でバイナリが異なるので注意。
なお全ての対応していないAPIを取り込んだわけではなくて、自分が必要な
ものだけを2,3個取り込んだ。
あとフォント名の取得が文字化けしていたので直した。
Download †
new wand API †
- compressionquality, GetCompressionQuality, SetCompressionQuality
JPEGの圧縮率の変更。
- format, GetFormat, SetFormat
GetFormatは前からあったのだが、フォーマットの変更をする
SetFormatが無かったので追加した。
Examples †
- 画像ファイルを開いてGIFのサムネイルをデータベースに格納
#======================================================
# Open a file and Create GIF thumbnail on memory
#======================================================
package require TclMagick
set THUMBSIZE 100
set w [magick create wand]
$w read c:/temp/テスト.bmp
set width [$w width]
set height [$w height]
if {$width > $height} {
$w scale $THUMBSIZE [expr {int(1.0 * $THUMBSIZE / $width * $height)}]
} else {
$w scale [expr {int(1.0 * $THUMBSIZE / $height * $width)}] $THUMBSIZE
}
$w format GIF
set thumbbin [$w writeblob]
magick delete $w
#======================================================
# Store the raw data to DB
#======================================================
package require sqlite3
sqlite db :memory:
db eval {create table t (id integer primary key, data blob);}
db eval {insert into t values(NULL, :thumbbin);}
#======================================================
# Load the image and show it
#======================================================
pacakge require Tk
set imgdata [lindex [db eval {select data from t where id=1;}] 0]
image create photo img -data $imgdata
pack [label .l -image img]
コメントをどーぞ †
[CategoryTclTk] [TclMagickの使い方]