Magick ベクターグラフィックス
MVG 概要 • 描画プリミティブ
この仕様は、ImageMagick で 2 次元ベクターおよびベクター/ラスター混在グラフィックスを記述するためのモジュール化された言語、Magick Vector Graphics(MVG)の機能と構文を定義します。この言語を使って、コマンドラインから、MVG ファイルから、SVG(Scalable Vector Graphics)ファイルから、または ImageMagick のプログラムインターフェースの 1 つから描画できます。たとえば、弧を描画するには次のコマンドを使います:
$ magick -size 100x60 canvas:skyblue -fill white -stroke black \
-draw "path 'M 30,40 A 30,20 20 0,0 70,20 A 30,20 20 1,0 30,40 Z '" \
arc.png
結果は次のとおりです:
描画が十分に複雑になったら、グラフィックプリミティブを MVG ファイルにまとめることを推奨します。この例では piechart.mvg を使います:
push graphic-context
viewbox 0 0 624 369
affine 0.283636 0 0 0.283846 -0 -0
push graphic-context
push graphic-context
fill 'darkslateblue'
stroke 'blue'
stroke-width 1
rectangle 1,1 2199,1299
pop graphic-context
push graphic-context
font-size 40
fill 'white'
stroke-width 1
text 600,1100 'Average: 20.0'
pop graphic-context
push graphic-context
fill 'red'
stroke 'black'
stroke-width 5
path 'M700.0,600.0 L340.0,600.0 A360.0,360.0 0 0,1 408.1452123287954,389.2376150414973 z'
pop graphic-context
push graphic-context
font-size 40
fill 'white'
stroke-width 1
text 1400,140 'MagickWand for PHP'
pop graphic-context
push graphic-context
font-size 30
fill 'white'
stroke-width 1
text 1800,140 '(10.0%)'
pop graphic-context
push graphic-context
fill 'red'
stroke 'black'
stroke-width 4
rectangle 1330,100 1370,140
pop graphic-context
push graphic-context
fill 'yellow'
stroke 'black'
stroke-width 5
path 'M700.0,600.0 L408.1452123287954,389.2376150414973 A360.0,360.0 0 0,1 976.5894480359858,369.56936567559273 z'
pop graphic-context
push graphic-context
font-size 40
fill 'white'
stroke-width 1
text 1400,220 'MagickCore'
pop graphic-context
push graphic-context
font-size 30
fill 'white'
stroke-width 1
text 1800,220 '(29.0%)'
pop graphic-context
push graphic-context
fill 'yellow'
stroke 'black'
stroke-width 4
rectangle 1330,180 1370,220
pop graphic-context
push graphic-context
fill 'fuchsia'
stroke 'black'
stroke-width 5
path 'M700.0,600.0 L976.5894480359858,369.56936567559273 A360.0,360.0 0 0,1 964.2680466142854,844.4634932636567 z'
pop graphic-context
push graphic-context
font-size 40
fill 'white'
stroke-width 1
text 1400,300 'MagickWand'
pop graphic-context
push graphic-context
font-size 30
fill 'white'
stroke-width 1
text 1800,300 '(22.9%)'
pop graphic-context
push graphic-context
fill 'fuchsia'
stroke 'black'
stroke-width 4
rectangle 1330,260 1370,300
pop graphic-context
push graphic-context
fill 'blue'
stroke 'black'
stroke-width 5
path 'M700.0,600.0 L964.2680466142854,844.4634932636567 A360.0,360.0 0 0,1 757.853099990584,955.3210081341651 z'
pop graphic-context
push graphic-context
font-size 40
fill 'white'
stroke-width 1
text 1400,380 'JMagick'
pop graphic-context
push graphic-context
font-size 30
fill 'white'
stroke-width 1
text 1800,380 '(10.6%)'
pop graphic-context
push graphic-context
fill 'blue'
stroke 'black'
stroke-width 4
rectangle 1330,340 1370,380
pop graphic-context
push graphic-context
fill 'lime'
stroke 'black'
stroke-width 5
path 'M700.0,600.0 L757.853099990584,955.3210081341651 A360.0,360.0 0 0,1 340.0,600.0 z'
pop graphic-context
push graphic-context
font-size 40
fill 'white'
stroke-width 1
text 1400,460 'Magick++'
pop graphic-context
push graphic-context
font-size 30
fill 'white'
stroke-width 1
text 1800,460 '(27.5%)'
pop graphic-context
push graphic-context
fill 'lime'
stroke 'black'
stroke-width 4
rectangle 1330,420 1370,460
pop graphic-context
push graphic-context
font-size 100
fill 'white'
stroke-width 1
text 100,150 'ImageMagick'
pop graphic-context
push graphic-context
fill 'none'
stroke 'black'
stroke-width 5
circle 700,600 700,960
pop graphic-context
pop graphic-context
pop graphic-context
次のコマンドで円グラフをレンダリングします:
$ magick mvg:piechart.mvg piechart.png
これは次のレンダリングを生成します:
ただし一般に、MVG は扱うのが十分に難しいため、おそらくプログラムで SVG 形式のグラフィックを生成したくなるでしょう。ImageMagick は SVG を自動的に MVG に変換して画像をレンダリングします。たとえば、次のコマンドで piechart.svg をレンダリングします:
$ magick mvg:piechart.svg piechart.jpg
これで MVG 言語で作ったのと同じ円グラフが生成されます。
描画は、多くの ImageMagick プログラムインターフェースからも利用できます。ImageMagick は描画 API 呼び出しを MVG に変換してレンダリングします。次は MagickWand 言語で書いた例です:
(void) PushDrawingWand(draw_wand);
{
const PointInfo points[6] =
{
{ 180,504 },
{ 282.7,578.6 },
{ 243.5,699.4 },
{ 116.5,699.4 },
{ 77.26,578.6 },
{ 180,504 }
};
DrawSetStrokeAntialias(draw_wand,True);
DrawSetStrokeWidth(draw_wand,9);
DrawSetStrokeLineCap(draw_wand,RoundCap);
DrawSetStrokeLineJoin(draw_wand,RoundJoin);
(void) DrawSetStrokeDashArray(draw_wand,0,(const double *)NULL);
(void) PixelSetColor(color,"#4000c2");
DrawSetStrokeColor(draw_wand,color);
DrawSetFillRule(draw_wand,EvenOddRule);
(void) PixelSetColor(color,"#800000");
DrawSetFillColor(draw_wand,color);
DrawPolygon(draw_wand,6,points);
}
(void) PopDrawingWand(draw_wand);
MVG 概要
MVG はコマンド間のすべての空白を無視します。これにより 1 行に複数の MVG コマンドを書けます。MVG を編集・読みやすくするため、各 MVG コマンドを改行で終えるのが一般的な慣習です。この構文説明では、理解を助けるため MVG シーケンスでインデントを使っています。インデントはサポートされますが必須ではありません。
メタファイルラッパー構文(スタンドアロンの MVG ファイルをサポートするため):
push graphic-context
viewbox 0 0 width height
[ any other MVG commands ]
pop graphic-context
パターン構文(コンテキストの保存と復元):
push pattern id x,y width,height
push graphic-context
[ drawing commands ]
pop graphic-context
pop pattern
例(%s は識別子文字列):
push defs
push pattern %s 10,10 20,20
push graphic-context
fill red
rectangle 5,5 15,15
pop graphic-context
push graphic-context
fill green
rectangle 10,10 20,20
pop graphic-context
pop pattern
pop defs
画像タイリングには次を使います:
push pattern id x,y width,height
image Copy ...
pop pattern
なお、パターンは次のように fill または stroke のどちらにも使えます:
stroke url(#%s)
または
fill url(#%s)
クリップパスはクリッピング領域を定義し、その内部の領域にのみ描画されます。クリッピング領域の外側はマスクされます。
push defs
push clip-path "myClipPath"
push graphic-context
rectangle 10,10 20,20
pop graphic-context
pop clip-path
pop defs
clip-path url(#myClipPath)
描画プリミティブ
MVG 描画プリミティブの完全な説明は次のとおりです:
| プリミティブ | 説明 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| affine sx,rx,ry,sy,tx,ty | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arc x0,y0 x1,y1 a0,a1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bezier x0,y0 ... xn,yn | Bezier(スプライン)は、形状を定義するのに 3 つ以上の x,y 座標を必要とする。最初と最後の点はノット(保持される座標)で、中間の座標は制御点。制御点が 2 つ指定されると、各端ノットとそれに順に対応する制御点の間の線が、その端での曲線の接線方向を決める。制御点が 1 つなら、端ノットからその 1 つの制御点への線が各端の接線方向を決める。制御点が 2 つを超えると、追加の制御点が組み合わさって曲線の中間形状を決める。複雑な曲線を描くには、Path プリミティブを使うか、各連続セグメントの開始・終了ノットを繰り返した複数の 4 点ベジエセグメントを描くことを強く推奨する。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| border-color color | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| circle originx,originy perimeterx,perimetery | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| clip-path url(name) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| clip-rule rule | 次のルールタイプから選ぶ:evenoddnonzero |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| clip-units units | 次の単位タイプから選ぶ:userSpaceuserSpaceOnUseobjectBoundingBox |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| color x,y method | 次のメソッドタイプから選ぶ:pointreplacefloodfillfilltoborderreset |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| compliance type | 次の準拠タイプから選ぶ: MVG または SVG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| decorate type | 次の装飾タイプから選ぶ:noneline-throughoverlineunderline |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ellipse centerx,centery radiusx,radiusy arcstart,arcstop | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fill color | これらの色のいずれかから選ぶ。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fill-opacity opacity | 不透明度は 0.0(完全透明)〜1.0(完全不透明)、またはパーセント(例: 50%)。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fill-rule rule | 次のルールタイプから選ぶ:evenoddnonzero |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| font name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| font-family family | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| font-size point-size | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| font-stretch type | 次のストレッチタイプから選ぶ:allnormalultra-condensedextra-condensedcondensedsemi-condensedsemi-expandedexpandedextra-expandedultra-expanded |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| font-style style | 次のスタイルから選ぶ:allnormalitalicoblique |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| font-weight weight | 次のウェイトから選ぶ:allnormalbold100200300400500600700800900 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gradient-units units | 次の単位から選ぶ:userSpaceuserSpaceOnUseobjectBoundingBox |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gravity type | 次の gravity タイプから選ぶ:NorthWestNorthNorthEastWestCenterEastSouthWestSouthSouthEast |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| image compose x,y width,height 'filename' | 次の合成操作から選ぶ:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interline-spacing pixels | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interword-spacing pixels | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| kerning pixels | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line x,y x1,y1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| matte x,y method | 次のメソッドから選ぶ:pointreplacefloodfillfilltoborderreset |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| offset offset | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| opacity opacity | パーセントを使う(例: 50%)。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path path | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| point x,y | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| polygon x,y x1,y1, ..., xn,yn | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| polyline x,y x1,y1, ..., xn,yn | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pop clip-path | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pop defs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pop gradient | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pop graphic-context | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pop pattern | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| push clip-path "name" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| push defs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| push gradient id linear x,y x1,y1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| push gradient id radial xc,cy xf,yf radius | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| push graphic-context { "id" } | id は任意 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| push pattern id x,y width,height | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rectangle x,y x1,y1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rotate angle | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| roundrectangle x,y x1,y1 width,height | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scale x,y | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| skewX angle | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| skewX angle | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stop-color color offset | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stroke color | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stroke-antialias 0 • 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stroke-dasharray none • numeric-list | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stroke-dashoffset offset | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stroke-linecap type | 次のキャップタイプから選ぶ:buttroundsquare |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stroke-linejoin type | 次のジョインタイプから選ぶ:bevelmiterround |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stroke-miterlimit limit | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stroke-opacity opacity | 不透明度は 0.0(完全透明)〜1.0(完全不透明)、またはパーセント(例: 50%)。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stroke-width width | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text "text" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text-antialias 0 • 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text-undercolor color | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| translate x,y | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use "url(#id)" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| viewbox x,y x1,y1 |
なお、プリミティブは大文字小文字を区別します。たとえば viewBox ではなく viewbox を使ってください。

