Treatment of images by ImageMagick and TeX



Treatment of images by ImageMagick and TeX

In this page, the methods for treatment and arrangement of images using ImageMagick and TeX are introduces.

Combine images by ImageMagick

ImageMagick command to make image 'out.png' by combining 'inp_1.png' and 'inp_2.png' vartically is shown below. For horizontal combining, '+append' option is used.


convert -append inp_1.png inp_2.png out.png

Add text on existing image using ImageMagick (Python program)

Python code using ImageMagick to add a text 'ss' at location (xx,yy) and to save image with a file name 'fnameW' is shown below. The origin of the coordinate (xx,yy) is located at left top of an image.


import os

cmd='convert -font Tahoma.ttf -pointsize 20 -annotate +{0:}+{1:} "{2:}" {3:} {4:}'.format(xx,yy,ss,fnameR,fnameW)
os.system(cmd)

Convert eps to png with triming

Imagemagick command to convert all eps files in a folder to png files with triming is shown below.


mogrify -trim -density 300 -bordercolor 'transparent' -border 10x10 -format png *.eps
rm *.eps

Convert pdf file by TeX to png with triming

Script to make pdf by TeX and convert pdf to png with triming is shown below. A peper size of TeX is set to A3.


platex tex_fig.tex
dvipdfmx -p a3 tex_fig.dvi

convert -trim -density 400 tex_fig.pdf -bordercolor 'transparent' -border 20x20 -quality 100 tex_fig.png

TeX (tex_fig.tex)

TeX source for arranging images on A3 paper is shown below. In this case, the documant for portrait paper arrangement is shown. If necessary, landscape mode can be used by '\usepackage[a3paper,landscape,...'


documentclass[english]{jsarticle}
\usepackage[a3paper,top=25mm,bottom=25mm,left=25mm,right=25mm]{geometry}
\usepackage[dvipdfmx]{graphicx}
\pagestyle{empty}

\begin{document}

\begin{center}
\begin{tabular}{cc}
\begin{minipage}{12.0cm}\vspace{0.2zh}\includegraphics[width=12.0cm,bb={0 0 1900 1122}]{_fig_gmt_xyz_0.png}\end{minipage}&
\begin{minipage}{12.0cm}\vspace{0.2zh}\includegraphics[width=12.0cm,bb={0 0 1900 1122}]{_fig_gmt_xyz_1.png}\end{minipage}\\
 & \\
 & \\
\begin{minipage}{12.0cm}\vspace{0.2zh}\includegraphics[width=12.0cm,bb={0 0 1900 1122}]{_fig_gmt_xyz_2.png}\end{minipage}&
\begin{minipage}{12.0cm}\vspace{0.2zh}\includegraphics[width=12.0cm,bb={0 0 1900 1122}]{_fig_gmt_xyz_3.png}\end{minipage}\\
 & \\
 & \\
\begin{minipage}{12.0cm}\vspace{0.2zh}\includegraphics[width=12.0cm,bb={0 0 1900 1122}]{_fig_gmt_xyz_4.png}\end{minipage}&
\begin{minipage}{12.0cm}\vspace{0.2zh}\includegraphics[width=12.0cm,bb={0 0 1900 1122}]{_fig_gmt_xyz_5.png}\end{minipage}\\
 & \\
 & \\
\begin{minipage}{12.0cm}\vspace{0.2zh}\includegraphics[width=12.0cm,bb={0 0 1900 1122}]{_fig_gmt_xyz_6.png}\end{minipage}&
\begin{minipage}{12.0cm}\vspace{0.2zh}\includegraphics[width=12.0cm,bb={0 0 1900 1122}]{_fig_gmt_xyz_7.png}\end{minipage}\\
\end{tabular}
\end{center}

\end{document}


inserted by FC2 system