GMT4で作成したepsをImageMagickのconvertを使ってpngに変換すると日本語が文字化けする。
状況は以下。
CentOS 7.8.2003 GMT 4.5.18 ImageMagick 7.0.10-18 ghostscript 9.25
テストコードを作る。
!/bin/bash gmtset HEADER_FONT = Helvetica title="漢字のテスト" pscoast -R105/150/18/50 -JM15 -G200 -B10:.${title}: -A0/0/1 -P -K cat <<EOF | pstext -R -JM -O -K 136 35 16 0 0 LM 日本の首都 Japanese 136 33 16 0 0 LM 東京 Tokyo
実行。
./test.sh > test.eps
gsで確認してみる。
gs -sDEVICE=x11 test.eps
gsのメッセージは以下の通り。
GPL Ghostscript 9.25 (2018-09-13) Copyright (C) 2018 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. Loading NimbusSans-Regular font from /usr/share/ghostscript/Resource/Font/NimbusSans-Regular... 4341540 2849313 6573768 5261322 1 done.
特に問題はなさそう。
ググるとGMTはUTF8非対応、EUC-JPに限る、とのこと。
それでは日本語をEUC-JPに変換。
#!/bin/bash gmtset HEADER_FONT = Helvetica title=`echo "漢字のTitle5" | iconv -f UTF8 -t EUCJP` pscoast -R105/150/18/50 -JM15 -G200 -B10:.${title}: -A0/0/1 -P -K cat <<EOF | iconv -f UTF8 -t EUCJP | pstext -R -JM -O -K 136 35 16 0 0 LM 日本の首都 Japanese 136 33 16 0 0 LM 東京 Tokyo EOF
結果は…。
まるで駄目。
フォントが無いのでしょうか。
IPAフォントをインストールする。
yum install ipa-mincho-fonts yum install ipa-gothic-fonts
フォントは以下にインストールされます。
/usr/share/fonts/ipa-mincho /usr/share/fonts/ipa-gothic
Ghostscript用にフォントを定義する。
vi /usr/share/ghostscript/Resource/Init/cidfmap
以下を追加。
/IPAMincho << /FileType /TrueType /Path (/usr/share/fonts/ipa-mincho/ipam.ttf) /CSI [(Japan1) 6] >> ; /IPAGothic << /FileType /TrueType /Path (/usr/share/fonts/ipa-gothic/ipag.ttf) /CSI [(Japan1) 6] >> ; /Ryumin-Light /IPAMincho ; /GothicBBB-Medium /IPAGothic ;
GMTの拡張フォントを定義する。
vi /usr/local/gmt4/share/pslib/CUSTOM_font_info.d
以下を追加。
Ryumin-Light-EUC-H 0.700 1 GothicBBB-Medium-EUC-H 0.700 1
pstext -Lで確認。
以下が追加されればOK。
35 Ryumin-Light-EUC-H 36 GothicBBB-Medium-EUC-H
フォントを修正する。
pstextの第5フィールドはフォント番号(35、36)。
#!/bin/bash gmtset HEADER_FONT = Ryumin-Light-EUC-H title=`echo "漢字のTitle5" | iconv -f UTF8 -t EUCJP` pscoast -R105/150/18/50 -JM15 -G200 -B10:.${title}: -A0/0/1 -P -K cat <<EOF | iconv -f UTF8 -t EUCJP | pstext -R -JM -O -K 136 35 16 0 35 LM 日本の首都 Japanese 136 33 16 0 36 LM 東京 Tokyo
再実行。
./test.sh > test.eps
gsで確認してみる。
gs -sDEVICE=x11 test.eps
大成功。
それではImageMagickのconvertでpngに変換してみます。
convert test.eps test.png
大量のエラーがでた。
convert: Postscript delegate failed `[ghostscript library 9.25] -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' -g595x842 -dEPSCrop '-sOutputFile=/tmp/magick-29126KuXCkbmoebnL%d' '-f/tmp/magick-29126N-1XF03kbCE8' '-f/tmp/magick-29126aC4JMA5jJ7Vv'': Error: /invalidfileaccess in /findfont Operand stack: 150 Ryumin-Light-EUC-H Execution stack: %interp_exit .runexec2 --nostringval-- .findfontop --nostringval-- 2 %stopped_push --nostringval-- .findfontop .findfontop false 1 %stopped_push 2047 1 3 %oparray_pop 2046 1 3 %oparray_pop 2026 1 3 %oparray_pop 1884 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- .findfontop --nostringval-- 2 %stopped_push --nostringval-- .findfontop 1976 2 4 %oparray_pop Dictionary stack:<a href="http://systemconcept.co.jp/blog/wp-content/uploads/2020/06/gmt4eps2png-suc.png"><img src="http://systemconcept.co.jp/blog/wp-content/uploads/2020/06/gmt4eps2png-suc-212x300.png" alt="" width="212" height="300" class="alignnone size-medium wp-image-1394" /></a> --dict:956/1684(ro)(G)-- --dict:0/20(G)-- --dict:78/200(L)-- --dict:125/250(L)-- Current allocation mode is local Last OS error: そのようなファイルやディレクトリはありません Current file position is 41000 GPL Ghostscript 9.25: Unrecoverable error, exit code 1 @ error/ghostscript-private.h/InvokeGhostscriptDelegate/171. convert: Postscript delegate failed `[ghostscript library 9.25] -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' -g595x842 -dEPSCrop '-sOutputFile=/tmp/magick-29126KuXCkbmoebnL%d' '-f/tmp/magick-29126N-1XF03kbCE8' '-f/tmp/magick-29126aC4JMA5jJ7Vv' -c showpage': Error: /invalidfileaccess in /findfont Operand stack: 150 Ryumin-Light-EUC-H Execution stack: %interp_exit .runexec2 --nostringval-- .findfontop --nostringval-- 2 %stopped_push --nostringval-- .findfontop .findfontop false 1 %stopped_push 2047 1 3 %oparray_pop 2046 1 3 %oparray_pop 2026 1 3 %oparray_pop 1884 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- .findfontop --nostringval-- 2 %stopped_push --nostringval-- .findfontop 1976 2 4 %oparray_pop Dictionary stack: --dict:956/1684(ro)(G)-- --dict:0/20(G)-- --dict:78/200(L)-- --dict:125/250(L)-- Current allocation mode is local Last OS error: そのようなファイルやディレクトリはありません Current file position is 41000 GPL Ghostscript 9.25: Unrecoverable error, exit code 1 @ error/ghostscript-private.h/InvokeGhostscriptDelegate/171. convert: no images defined `test.png' @ error/convert.c/ConvertImageCommand/3282.
cidfmapで伝えたはずのパスが伝わっていないようにみえる。
ググるとGS_LIBという環境変数で伝えることができるみたいです。
echo $GSLIBとやってみるが、何も入っていない。
現在はあまり使わないそうです。
他に方法があるのだろうが、とりあえずこれを試す。
設定するのは先ほどインストールしたIPAフォントのパスです。
export GS_LIB=/usr/share/fonts
再挑戦。
convert test.eps test.png