HTML5やRetinaディスプレイの登場があって、SVGに注目が集まっています。ベクターベースなので拡大しても綺麗なままで表現できます。しかしWebブラウザでも表示できますが、良いビューワーがなく再利用性が高くないのが現状です。 そこで使ってみたいのがsvgexportです。SVGファイルを画像やPDFにエクスポートできるソフトウェアです。

svgexportの使い方

インストールはnpmでできます。

$ npm install svgexport -g

使い方は次のようになります。

svgexport <input file/> <output file> <options>
svgexport <datafile>

<options>        [<format>] [<quality>] [<input viewbox/>] [<output size>] [<pdf size>]
<format>         png|jpeg|jpg|pdf
                 If not specified, it will be inferred from output file extension or defaults to "png".
<quality>        1%-100%
<input viewbox/>  [<left>:<top>:]<width>:<height>
                 If input viewbox is not specified it will be inferred from input file.
<output size>    <scale>x|[<width>]:[<height>]
                 If specified as width:height, viewbox will be centered and cropped to match output aspect ratio.
<pdf size>       <width>(mm|cm|in|px):<height>(mm|cm|in|px)
                 A3|A4|A5|Legal|Letter|Tabloid [portrait|landscape]

<datafile>       A JSON file with following content:
                 [ {
                   "input" : "<input file/> <options>",
                   "output": [ "<output file> <options>", ... ]
                 }, ...]
                 Input file options are merged with and overridden by output file options.
                 Instead of a JSON file, a Node module which exports same content can be provided.

基本的には入力ファイル(SVG)を指定して、出力形式(PNG、JPEG、PDF)を指定するだけです。

出力例。PNGです。

大きさは自由に変更できます。

PDFによる出力例。

SVGでファイルを作成すれば、後は大きさを自由に変更して画像やPDFが作成できるというのが面白さでしょう。今後ますますSVGの需要が高まりそうなソフトウェアです。

svgexportはnode/JavaScript製のソフトウェア(ソースコードは公開されていますがライセンスは明記されていません)です。

shakiba/svgexport