Friday, May 20, 2011

PythonMagickで画像を拡散させる

PythonMagickで画像を拡散させるには、以下のコードのようにspreadを使用します。

# coding=UTF-8
import PythonMagick

# 画像を拡散させる
img = PythonMagick.Image("SF.JPG")
img.spread(5)

img.write("img17.jpg")

元画像


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Wednesday, May 18, 2011

PythonMagickで画像を反転させる

PythonMagickで画像を反転させるには、以下のコードのようにnegateを使用します。

# coding=UTF-8
import PythonMagick

# 画像を反転させる
img = PythonMagick.Image("SF.JPG")
img.negate()

img.write("img16.jpg")

元画像


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Monday, May 16, 2011

PythonMagickで画像をエンボス処理する

PythonMagickで画像をエンボス処理するには、以下のコードのようにembossを使用します。

# coding=UTF-8
import PythonMagick

# 画像をエンボス処理する
img = PythonMagick.Image("SF.JPG")
img.emboss(1,1)

img.write("img15.jpg")

元画像


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Saturday, May 14, 2011

PythonMagickで単色の画像を作成する

PythonMagickで単色の画像を作成するには、以下のコードを実行します。

# coding=UTF-8
import PythonMagick

# 単色の画像を作成する
img = PythonMagick.Image(
PythonMagick._PythonMagick.Geometry(150, 150),
"#ccddff")

img.write("img14.jpg")

出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Thursday, May 12, 2011

PythonMagickで2つの画像を重ね合わせる

PythonMagickで2つの画像を重ね合わせるには、以下のコードのようにcompositeを使用します。

# coding=UTF-8
import PythonMagick

# 2つの画像を重ね合わせる
img = PythonMagick.Image("SF.JPG")
img2 = PythonMagick.Image("sample3b.jpg")

img.composite(img2, 10, 10,
PythonMagick._PythonMagick.CompositeOperator.SrcOverCompositeOp);

img.write("img13.jpg")

元画像1


元画像2


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Tuesday, May 10, 2011

PythonMagickで任意の色調のモノクローム画像に変換する

PythonMagickで任意の色調のモノクローム画像に変換するには、以下のコードの様にcolorizeを使用します。

# coding=UTF-8
import PythonMagick

# 水色っぽい色調のモノクローム画像に変換
img = PythonMagick.Image("SF.JPG")
img.modulate(100, 0, 0)
img.colorize(40, PythonMagick._PythonMagick.Color("#ccddff"))
img.write("img12a.jpg")

# ピンクっぽい色調のモノクローム画像に変換
img = PythonMagick.Image("SF.JPG")
img.modulate(100, 0, 0)
img.colorize(40, PythonMagick._PythonMagick.Color("pink"))
img.write("img12b.jpg")


元画像


出力画像1


出力画像2


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Sunday, May 08, 2011

PythonMagickで画像を切り落とす

PythonMagickで画像を切り落とすには、以下のコードの様にchopを使用します。

# coding=UTF-8
import PythonMagick

# 上40ピクセルを切り落とす
img = PythonMagick.Image("SF.JPG")
img.chop(PythonMagick._PythonMagick.Geometry(0, 40))
img.write("img11a.jpg")

# 下40ピクセルを切り落とす
img = PythonMagick.Image("SF.JPG")
img.chop(PythonMagick._PythonMagick.Geometry("0x40+0+160"))
img.write("img11b.jpg")


元画像


出力画像1


出力画像2


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Friday, May 06, 2011

PythonMagickで画像を木炭画調に変換する

PythonMagickで画像を木炭画調に変換するには、以下のコードの様にcharcoalを使用します。

# coding=UTF-8
import PythonMagick

# 画像を木炭画調に変換する
img = PythonMagick.Image("SF.JPG")
img.charcoal(2)

img.write("img10.jpg")


元画像


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Wednesday, May 04, 2011

PythonMagickで画像に枠を追加する

PythonMagickで画像に枠を追加するには、以下のコードの様にborderを使用します。

# coding=UTF-8
import PythonMagick

# 画像に枠を追加する
img = PythonMagick.Image("SF.JPG")

# 枠の色を指定
img.borderColor(PythonMagick._PythonMagick.Color("white"))
# 枠を描画
img.border(PythonMagick._PythonMagick.Geometry(8,8))

img.borderColor(PythonMagick._PythonMagick.Color("#918164"))
img.border(PythonMagick._PythonMagick.Geometry(4,4))

img.write("img9.jpg")


元画像


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Monday, May 02, 2011

PythonMagickで画像に日本語を描画する

PythonMagickで画像に日本語を描画するには、以下のコードの様にannotateを使用します。

# coding=UTF-8
import PythonMagick

# 画像に日本語を描画する
img = PythonMagick.Image("SF.JPG")
# 文字列の色
img.fillColor(PythonMagick._PythonMagick.Color("#ffff00"))
# 使用するフォント
img.font("/usr/share/fonts/truetype/ttf-japanese-gothic.ttf")
# フォントサイズ(ポイント)
img.fontPointsize(30)
img.annotate("日本語",
PythonMagick._PythonMagick.Geometry(0,0, 50, 150),
PythonMagick._PythonMagick.GravityType.NorthWestGravity)
img.write("img8.jpg")


元画像


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Saturday, April 30, 2011

PythonMagickで画像にぼかしをかける

PythonMagickで画像にぼかしをかけるには、以下のコードのようにblurを使用します。

# coding=UTF-8
import PythonMagick

# 画像にぼかしをかける
img = PythonMagick.Image("SF.JPG")
img.blur(0,1)
img.write("img7.jpg")


元画像


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Thursday, April 28, 2011

PythonMagickで画像を回転させる

PythonMagickで画像を回転させるには、以下のコードのようにrotateを使用します。

# coding=UTF-8
import PythonMagick

# 画像を回転させる
img = PythonMagick.Image("SF.JPG")
# 余白の背景色を指定
img.backgroundColor(PythonMagick._PythonMagick.Color("#7799dd"))
img.rotate(30)
img.write("img6.jpg")


元画像


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Tuesday, April 26, 2011

PythonMagickで画像をスクロールさせる

PythonMagickで画像をスクロールさせるには、以下のコードのようにrollを使用します。

# coding=UTF-8
import PythonMagick

# 横方向に20ピクセルスクロール
img = PythonMagick.Image("SF.JPG")
img.roll(PythonMagick._PythonMagick.Geometry(0, 0, 20, 0))
img.write("img5a.jpg")

# 縦方向に20ピクセルスクロール
img2 = PythonMagick.Image("SF.JPG")
img2.roll(PythonMagick._PythonMagick.Geometry(0, 0, 0, 20))
img2.write("img5b.jpg")


元画像


出力画像1


出力画像2


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Sunday, April 24, 2011

PythonMagickで画像の一部を切り取る

PythonMagickで画像の一部を切り取るには、以下のコードのようにcropを使用します。

# coding=UTF-8
import PythonMagick

# 画像の一部分を切り取る
img = PythonMagick.Image("SF.JPG")
img.crop(PythonMagick._PythonMagick.Geometry(50,100,100,100))
img.write("img4.jpg")


元画像


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Monday, April 11, 2011

PythonMagickで画像をリサイズする

PythonMagickで画像をリサイズするには、以下のコードを実行します。

# coding=UTF-8
import PythonMagick

# リサイズ
img = PythonMagick.Image("SF.JPG")
img.sample(PythonMagick._PythonMagick.Geometry(100,100))
img.write("img3.jpg")

元画像


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Friday, April 08, 2011

PythonMagickで画像を上下反転・左右反転させる

PythonMagickで画像を上下反転・左右反転させるには、以下のコードを実行します。

# coding=UTF-8
import PythonMagick

# 上下反転
img = PythonMagick.Image("SF.JPG")
img.flip()
img.write("img2.jpg")

# 左右反転
img2 = PythonMagick.Image("SF.JPG")
img2.flop()
img2.write("img3.jpg")

元画像


出力画像1


出力画像2


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Wednesday, April 06, 2011

PythonMagickで画像を白黒に変換する

PythonMagickで画像を白黒に変換するには、以下のコードを実行します。

# coding=UTF-8
import PythonMagick

img = PythonMagick.Image("SF.JPG")
img.modulate(100,0,0)
img.write("img1.jpg")

元画像


出力画像


※ubuntuでPythonMagickをインストールするには、以下のコマンドを実行します。
sudo apt-get install python-pythonmagick

動作環境
python 2.6.6, python-pythonmagick 0.9.1

Sunday, April 03, 2011

Graphvizで出力イメージを縮小する

Graphvizで出力イメージを縮小するには、以下のようにviewportの3番目のパラメータを指定します。.5を指定することで1/2に縮小されます。

実行コマンド
dot -Gviewport=150,150,.5 -Gresolution=72 -Tpng graph37.dot -o test37.png

graph37.dot(UTF-8で保存)
digraph graph37
{
node [fontname="MS Gothic"];
項目1 -> 項目2 -> 項目3;
項目2 -> 項目4;
}


出力画像


動作環境
Graphviz 2.26.3

関連情報
Graphvizまとめ
graphvizのサイト
http://graphviz.org/

Friday, April 01, 2011

Graphvizで背景を透明にして半透明のノードを描画する

Graphvizで背景を透明にして半透明のノードを描画するには、以下のようにcolorでアルファ値を指定します。

graph36.dot(UTF-8で保存)
digraph graph36
{
graph[bgcolor="#00000000"];
node [fontname="MS Gothic", style="filled",
fillcolor="#00000080"];
項目1 -> 項目2 -> 項目3;
項目2 -> 項目4;
}

実行コマンド
dot -Gviewport=200,200 -Gresolution=72 -Tpng graph36.dot -o test36.png

出力画像


動作環境
Graphviz 2.26.3

関連情報
Graphvizまとめ
graphvizのサイト
http://graphviz.org/

Wednesday, March 30, 2011

Graphvizのcircoで有方向グラフを描画する

Graphvizのcircoで有方向グラフを描画するには、以下のようなコマンドを実行します。

実行コマンド
circo -Gviewport=500,500 -Gresolution=72 -Tpng graph35.dot -o test35.png

graph35.dot(UTF-8で保存)
digraph graph35
{
node [fontname="MS Gothic"];
項目1 -> 項目2 -> 項目3;
項目3 -> 項目4 -> 項目5;
項目5 -> 項目6 -> 項目1;
項目2 -> 項目5;
}


出力画像


動作環境
Graphviz 2.26.3

関連情報
Graphvizまとめ
graphvizのサイト
http://graphviz.org/