Top/article/Command-to-rotate-eps
English | Japanese
English | Japanese

Menu

  • Top
  • Akihiko Yamaguchi 山口 明彦
  • Project プロジェクト
  • Text テキスト
  • Recent articles 最近の記事
  • Articles 記事一覧 (a to z)
  • Search 検索

Tags タグ †

  • [c++][bash][python][latex][php]
  • [linux][windows][mac][android]
  • [math][algorithm][idea][trick]
  • [liboctave][opencv][git][ros]
  • [setting][bug][general]
↑

Recent articles 最近の記事 †

2019-07-02
  • article/Display-Unix-Time
  • article/Synchronize-Linux-Time-to-Remote
2018-09-27
  • article/python-multimode-singleton
2018-09-02
  • article/rosinstall-git-default-remote
2017-07-28
  • article/SubMenu
2017-03-05
  • article/Import-a-different-version-of-OpenCV-in-Python
2015-08-17
  • article/DRC-finals-2015
2015-01-05
  • article/Upgrade-Android-to-Lollipop
2015-01-01
  • article/Kernel-panic-of-Linux-when-using-Xtion
  • article/Do-not-skip-freeing-data-when-using-tri-mesh-in-ODE
Access: 1/3419 - Admin
These search terms have been highlighted:[bash]

Command to rotate eps

eps を回転するコマンド

[latex][trick][linux][bash]
2011-10-05

epsffit というコマンドを使えば,eps を回転できる.epsffit は少々使い勝手が悪いので,使いやすくするスクリプトを書いてみた.

epsffit は,次のようにすると,反時計周りに90度回転できる.

epsffit -r LLX LLY URX URY INPUT.eps OUTPUT.eps

ここで LLX LLY URX URY は bounding box (すべて整数値).

以下の点が使いにくい:

  • bounding box を手動で指定する必要がある.
  • 回転角が固定.

そこで,オリジナルの eps ファイルから bounding box を自動抽出し,90度刻みの任意の角に回転できるようにするスクリプトを書いた.

epsmanip

#!/bin/bash

function ask
{
  while true; do
    echo -n '  (y|n) > '
    read s
    if [ "$s" == "y" ];then return 0; fi
    if [ "$s" == "n" ];then return 1; fi
  done
}

infile=
outfile=
angle=0

while true; do
  case "$1" in
    -r|-rot)
      case "$2" in
        0)  angle=0 ;;
        90)  angle=1 ;;
        180)  angle=2 ;;
        270)  angle=3 ;;
        -90)  angle=3 ;;
        -180)  angle=2 ;;
        -270)  angle=1 ;;
        *)  echo "choose angle from {-270,-180,-90,0,90,180,270}"; exit 1 ;;
      esac
      shift 2 ;;
    '') shift; break ;;
    *)
      if [ -z "$infile" ];then  infile=$1
      elif [ -z "$outfile" ];then  outfile=$1
      else echo "too many options"; exit 1
      fi
      shift;;
  esac
done

if ! [ -f $infile ];then
  echo "input file does not exist: $infile"
  exit 1
fi
if [ -z "$outfile" ];then outfile=$infile; fi

bbox=`grep '%%BoundingBox' $infile | sed 's/.*BoundingBox\s*:\(\(\s[0-9]\+\)*\)/\1/g'`

cp $infile /tmp/epsmanip$$.1
for ((i=0;i<$angle;i+=1));do
  epsffit -r $bbox /tmp/epsmanip$$.1 /tmp/epsmanip$$.2
  mv /tmp/epsmanip$$.2 /tmp/epsmanip$$.1
done

if [ -f $outfile ];then
  echo "output file exists: $outfile"
  echo "overwrite?"
  if ! ask; then
    rm -f /tmp/epsmanip$$.1
    exit 1;
  fi
fi
mv /tmp/epsmanip$$.1 $outfile

例えば時計周りに90度回転するには,

epsmanip -r -90 INPUT.eps OUTPUT.eps

とする.

注意

  • インターフェイスはちゃんと作ってない.
  • デバッグはまじめにやってない.

参考記事

  • Inkscape で eps をきれいに出力する方法



Last-modified:2015-01-01 (Thu) 09:26:41 (3803d)
Link: article/Beautiful-eps-generation-with-Inkscape(3804d)
Site admin: Akihiko Yamaguchi.
Written by: Akihiko Yamaguchi.
System: PukiWiki 1.5.0. PHP 5.2.17. HTML conversion time: 0.008 sec.