从 PSTricks 绘图创建 PNG 图像

从 PSTricks 绘图创建 PNG 图像

我可以将下面的绘图转换为 PNG 图像吗?如果可以,我该怎么做?

% xelatex <filename>.tex

\documentclass[11pt]{article}

\usepackage{fontspec}
\setmainfont{Calibri}
\usepackage[margin = 2cm]{geometry}
\usepackage{pstricks}
\usepackage{rotating}

\pagestyle{empty}


\begin{document}

\begin{figure}[htbp]
\centering
\psset{
  unit = 2.4,
  fillstyle = solid,
  opacity = 0.3
}
\begin{pspicture}(-3.5,-1.75)(3.5,4.25)
\psellipse[rot = -50, fillcolor = blue](1.5,0.5)(1.5,3)
\psellipse[rot = 50,  fillcolor = red](-1.5,0.5)(1.5,3)
\psellipse[rot = -50, fillcolor = green](0,1.8)(1.5,3)
\psellipse[rot = 50,  fillcolor = yellow](0,1.8)(1.5,3)
\rput(-3.57,1.93){
  \begin{rotate}{45}
    \shortstack[c]{%
      Religious\strut\\[-0.75ex]
      Bollocks\strut}
  \end{rotate}}
\rput(-2.1,3.2){
  \begin{rotate}{45}
    \shortstack[c]{%
      Quackery\strut\\[-0.75ex]
      Bollocks\strut}
  \end{rotate}}
\rput(3.07,2.33){
  \begin{rotate}{315}
    \shortstack[c]{%
      Paranormal\strut\\[-0.75ex]
      Bollocks\strut}
  \end{rotate}}
\rput(1.52,3.78){
  \begin{rotate}{315}
    \shortstack[c]{%
      Pseudoscientific\strut\\[-0.75ex]
      Bollocks\strut}
  \end{rotate}}
\rput(0,0.4){\large Scientology}
{\footnotesize
\rput(0.5,0){\shortstack[c]{%
  Psychic\strut\\[-0.75ex]
  Surgery\strut}}
\rput(1.5,0.1){Aura Therapy}
\rput(1.7,0.5){Reiki}
\rput(1.9,0.9){Chakra}
\rput(0.6,1){Qi}
\rput(0.9,1.3){Feng Shui}
\rput(1.2,1.6){Past Life Regression}
{\tiny
\rput(2.1,2.45){Ley Lines}
\rput(1.95,2.3){Orgone Energy}
\rput(1.97,2.15){Palmistry}
\rput(1.98,2){Orbs}}
\rput(2.9,1.9){Crop Circles}
\rput(3.1,1.6){Ectoplasm}
\rput(3.1,1.3){Telepathy}
\rput(2.7,1){Tarot}
\rput(3.2,0.9){\shortstack[c]{%
  Crystal\strut\\[-0.75ex]
  Power\strut}}
\rput(2.9,0.5){\shortstack[c]{%
  Automaric\strut\\[-0.75ex]
  Writing\strut}}
\rput(2.75,0.1){Geomancy}
\rput(2.55,-0.25){Levitation}
\rput(2.1,-0.5){Remote Writing}
\rput(1.92,-0.75){Ghosts}
\rput(1.35,-0.75){Psychics}
\rput(1.5,-1){Poltergeist}
\rput(1.2,-1.2){Seances}
\rput(-0.5,-0.5){Exorcism}
\rput(-0.5,-0.8){Ouija Boards}
\rput(-0.5,-1.1){Spiritualism}
\rput(0,-1.4){Stigmata}
\rput(0.5,-0.5){Akashic Record}
\rput(0.5,-0.8){Occult}
\rput(0.5,-1.1){Voodoo}
\rput(-0.5,0){\shortstack[c]{%
  Bible\strut\\[-0.75ex]
  Code\strut}}
\rput(-1.9,0.95){\shortstack[c]{%
  Apocalyptic\strut\\[-0.75ex]
  Prophecies\strut}}
\rput(-1.7,0.6){Intelligent Design}
\rput(-1.6,0.3){Out of Body Experience}
\rput(-1.5,0){Turin Shroud}
\rput(-1.2,1.6){Antrophosophy}
\rput(-0.8,1.1){Alphabiotics}
\rput(0,3.2){Anti Vaccination}
\rput(-0.4,2.9){Cupping}
\rput(0.4,2.9){Chiropratic}
\rput(0,2.6){Bioharmonics}
\rput(-0.4,2.3){Reflexology}
\rput(0.4,2.3){Rolfing}
\rput(0,2){Applied Kinesiology}
\rput(0,1.75){Ear Candles}
\rput(0,1.5){Detox}
{\scriptsize
\rput(0.7,3.7){Chemtrails}
\rput(1,3.525){Astrology}
\rput(1.3,3.35){Numerology}
\rput(1.6,3.175){Hollow Earth}
\rput(1.8,3){Moon Landing Denial}
\rput(1.8,2.825){Dowsing}
\rput(1.8,2.65){Bigfoot}}
\rput(-0.7,3.6){Shiatsu}
\rput(-1,3.4){Acupuncture}
\rput(-1.3,3.2){Homeopathy}
\rput(-1.6,3){Aromatherapy}
\rput(-1.8,2.8){Ayurvedic Medicine}
{\tiny
\rput(-2.1,2.4){\shortstack[c]{%
  Angel\strut\\[-0.75ex]
  Therapy\strut}}
\rput(-1.98,2.15){\shortstack[c]{%
  Faith\strut\\[-0.75ex]
  Healing\strut}}}
\rput(-2.8,1.9){Miracles}
\rput(-3,1.55){\shortstack[c]{%
  Religious\strut\\[-0.75ex]
  Fundamentalism\strut}}
\rput(-3.1,1.2){Reincarnation}
\rput(-3.1,0.85){Creationism}
\rput(-3,0.5){Prayer}
\rput(-2.8,0.15){\shortstack[c]{%
  Transsub-\strut\\[-0.75ex]
  stantiation\strut}}
\rput(-2.58,-0.2){Holy Relics}
\rput(-2.2,-0.5){Angels}
\rput(-1.65,-0.8){The Trinity}
\rput(-1.3,-1.1){Karma}}
\end{pspicture}
\end{figure}

\end{document}

输出

答案1

步骤1

确保您已经安装了 ImageMagick。

第2步

为了简单起见,我创建了converter.tex嵌入代码如下,

% this file name is converter.tex
% compile it with pdflatex -shell-escape converter.tex
\documentclass[preview,border=12pt]{standalone}
\usepackage{filecontents}

\begin{filecontents*}{diagram.tex}

\documentclass[pstricks,border=12pt,11pt]{standalone}


\usepackage{pstricks}
\usepackage{rotating}

\begin{document}


\psset{
  unit = 2.4,
  fillstyle = solid,
  opacity = 0.3
}
\begin{pspicture}(-4,-1.75)(4,4.25)
\psellipse[rot = -50, fillcolor = blue](1.5,0.5)(1.5,3)
\psellipse[rot = 50,  fillcolor = red](-1.5,0.5)(1.5,3)
\psellipse[rot = -50, fillcolor = green](0,1.8)(1.5,3)
\psellipse[rot = 50,  fillcolor = yellow](0,1.8)(1.5,3)
\rput(-3.57,1.93){
  \begin{rotate}{45}
    \shortstack[c]{%
      Religious\strut\\[-0.75ex]
      Bollocks\strut}
  \end{rotate}}
\rput(-2.1,3.2){
  \begin{rotate}{45}
    \shortstack[c]{%
      Quackery\strut\\[-0.75ex]
      Bollocks\strut}
  \end{rotate}}
\rput(3.07,2.33){
  \begin{rotate}{315}
    \shortstack[c]{%
      Paranormal\strut\\[-0.75ex]
      Bollocks\strut}
  \end{rotate}}
\rput(1.52,3.78){
  \begin{rotate}{315}
    \shortstack[c]{%
      Pseudoscientific\strut\\[-0.75ex]
      Bollocks\strut}
  \end{rotate}}
\rput(0,0.4){\large Scientology}
{\footnotesize
\rput(0.5,0){\shortstack[c]{%
  Psychic\strut\\[-0.75ex]
  Surgery\strut}}
\rput(1.5,0.1){Aura Therapy}
\rput(1.7,0.5){Reiki}
\rput(1.9,0.9){Chakra}
\rput(0.6,1){Qi}
\rput(0.9,1.3){Feng Shui}
\rput(1.2,1.6){Past Life Regression}
{\tiny
\rput(2.1,2.45){Ley Lines}
\rput(1.95,2.3){Orgone Energy}
\rput(1.97,2.15){Palmistry}
\rput(1.98,2){Orbs}}
\rput(2.9,1.9){Crop Circles}
\rput(3.1,1.6){Ectoplasm}
\rput(3.1,1.3){Telepathy}
\rput(2.7,1){Tarot}
\rput(3.2,0.9){\shortstack[c]{%
  Crystal\strut\\[-0.75ex]
  Power\strut}}
\rput(2.9,0.5){\shortstack[c]{%
  Automaric\strut\\[-0.75ex]
  Writing\strut}}
\rput(2.75,0.1){Geomancy}
\rput(2.55,-0.25){Levitation}
\rput(2.1,-0.5){Remote Writing}
\rput(1.92,-0.75){Ghosts}
\rput(1.35,-0.75){Psychics}
\rput(1.5,-1){Poltergeist}
\rput(1.2,-1.2){Seances}
\rput(-0.5,-0.5){Exorcism}
\rput(-0.5,-0.8){Ouija Boards}
\rput(-0.5,-1.1){Spiritualism}
\rput(0,-1.4){Stigmata}
\rput(0.5,-0.5){Akashic Record}
\rput(0.5,-0.8){Occult}
\rput(0.5,-1.1){Voodoo}
\rput(-0.5,0){\shortstack[c]{%
  Bible\strut\\[-0.75ex]
  Code\strut}}
\rput(-1.9,0.95){\shortstack[c]{%
  Apocalyptic\strut\\[-0.75ex]
  Prophecies\strut}}
\rput(-1.7,0.6){Intelligent Design}
\rput(-1.6,0.3){Out of Body Experience}
\rput(-1.5,0){Turin Shroud}
\rput(-1.2,1.6){Antrophosophy}
\rput(-0.8,1.1){Alphabiotics}
\rput(0,3.2){Anti Vaccination}
\rput(-0.4,2.9){Cupping}
\rput(0.4,2.9){Chiropratic}
\rput(0,2.6){Bioharmonics}
\rput(-0.4,2.3){Reflexology}
\rput(0.4,2.3){Rolfing}
\rput(0,2){Applied Kinesiology}
\rput(0,1.75){Ear Candles}
\rput(0,1.5){Detox}
{\scriptsize
\rput(0.7,3.7){Chemtrails}
\rput(1,3.525){Astrology}
\rput(1.3,3.35){Numerology}
\rput(1.6,3.175){Hollow Earth}
\rput(1.8,3){Moon Landing Denial}
\rput(1.8,2.825){Dowsing}
\rput(1.8,2.65){Bigfoot}}
\rput(-0.7,3.6){Shiatsu}
\rput(-1,3.4){Acupuncture}
\rput(-1.3,3.2){Homeopathy}
\rput(-1.6,3){Aromatherapy}
\rput(-1.8,2.8){Ayurvedic Medicine}
{\tiny
\rput(-2.1,2.4){\shortstack[c]{%
  Angel\strut\\[-0.75ex]
  Therapy\strut}}
\rput(-1.98,2.15){\shortstack[c]{%
  Faith\strut\\[-0.75ex]
  Healing\strut}}}
\rput(-2.8,1.9){Miracles}
\rput(-3,1.55){\shortstack[c]{%
  Religious\strut\\[-0.75ex]
  Fundamentalism\strut}}
\rput(-3.1,1.2){Reincarnation}
\rput(-3.1,0.85){Creationism}
\rput(-3,0.5){Prayer}
\rput(-2.8,0.15){\shortstack[c]{%
  Transsub-\strut\\[-0.75ex]
  stantiation\strut}}
\rput(-2.58,-0.2){Holy Relics}
\rput(-2.2,-0.5){Angels}
\rput(-1.65,-0.8){The Trinity}
\rput(-1.3,-1.1){Karma}}
\end{pspicture}


\end{document}

\end{filecontents*}

\usepackage{pgffor}
\usepackage{graphicx}
\foreach \compiler/\ext in {latex/tex,dvips/dvi,{ps2pdf -dAutoRotatePages=/None}/ps}{\immediate\write18{\compiler\space diagram.\ext}}

% converting...
\immediate\write18{convert diagram.pdf diagram.png}
\begin{document}
\begin{center}
\includegraphics[scale=.5]{diagram.png}
\end{center}

Locate \verb|diagram.png| in the folder in which you saved this source code (\verb|converter.tex|)
\end{document}

步骤3

编译converter.texpdflatex -shell-escape converter.tex完成!以下内容证明了我所说的。

在此处输入图片描述

步骤 4(可选的整理)

如果要删除辅助文件,请添加

\foreach \ext in {dvi,ps,log,aux,pdf}{\immediate\write18{cmd /c del diagram.\ext}}

以下

\foreach \compiler/\ext in {latex/tex,dvips/dvi,{ps2pdf -dAutoRotatePages=/None}/ps}{\immediate\write18{\compiler\space diagram.\ext}}

注意:它仅适用于 Windows 机器,因为cmd-like 命令在其他操作系统上可能具有不同的名称和语法。

相关内容