Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How to obtain this graph in a PNG/GIF/JPG graph with transparent background?

\documentclass[12pt,a4paper,x11names]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{latexsym}
%\usepackage[x11names,table]{xcolor} % colores por nombres y tablas. dddd%

\usepackage{datetime}
\settimeformat{ampmtime}

\usepackage{hyperref} %Dudo si este paquete puede dar error al compilar con LATEX (no PDFLATEX)
\hypersetup{colorlinks=true, urlcolor=blue}


\headheight=15pt  %/ MARGENES y otros

\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}

%--------   Paquetes para uso con PSTricks  -----------------------------------------------%
\usepackage{pstricks}
% -------- Paquetes de pst-all \usepackage{pst-all}   paquete pstricks para las figuras en postcript
\usepackage{pst-plot}
\usepackage{pst-node}
\usepackage{pst-tree}
\usepackage{pst-grad}
\usepackage{pst-coil}
\usepackage{pst-text}
\usepackage{pst-3d}
\usepackage{pst-eps}
\usepackage[tiling]{pst-fill}
\usepackage{pstricks-add}
\usepackage{multido}
% ---- Fin Paquetes de pst-all
\usepackage{pst-fr3d}               % paquete pstricks para las figuras en postcript
\usepackage{pst-infixplot,pst-math} % paquete pstricks para las figuras en postcript
%%%%%   Paquetes para definir los "ladillos" de la parte superior de las páginas, los capítulos, las secciones y más cosas.
%%%%% La explicación de cómo se hace todo esto viene en las instrucciones que están incluidas en la instalacion.
\usepackage[clearempty,explicit,pagestyles]{titlesec}
\usepackage{titletoc}
%%%% Paquete para hacer los gráficos.   % OJO.- En alguna compilación me daba incompatibilidad de esta opción dvips con la clase article %
\usepackage[dvips]{graphicx}  % OJO.- HE QUITADO [dvips] antes de {graphicx} porque me daba error , y me pedía poner [dvips] en la clase principal, pero aparecía atenuado en article, como si no aceptase esta opción. Cargar despues de paquetes PSTricks
%--------   Fin Paquetes para uso con PSTricks  -------------------------------------------%

\usepackage{graphicx}    % paquete para insertar gráficos
\usepackage{epstopdf}    % para que funcioneen los eps con pdflatex
\usepackage{multicol}    % para incluir columnas multiples

\usepackage{marginnote}  % para crear notas al margen

\usepackage{mathpazo}    % para usar la fuente MathPAzo que me gusta más, yse lee bien.

\usepackage{fix-cm}  
\usepackage{anyfontsize} %

\usepackage{fancyhdr}   % Paquete para cabeceras y pies en cada página.
\pagestyle{fancy}       % seleccionamos un estilo

\renewcommand{\labelenumi}{\arabic{enumi}.- }   % personalizado a mi gusto los itemize.

\graphicspath{{G:/}{G:/Rafa/TEX Arquivos/}}

\settimeformat{ampmtime} % para incrustar fecha y hora en los documentos.

\spanishdecimal{.}       % Para usar el punto decimal, y no confundirlo con las comas.

% ///////////////////////////////////////////////////////////////////////////// %
%\cfoot{\includegraphics[width=11cm]{heado2}} % imagen centro del pie
\lhead{M.I.} % texto izquierda de la cabecera
%\chead{\today \;-\;  \currenttime } % texto centro de la cabecera
\rhead{Right Header} % número de página a la derecha
% - - -  - - - - - - - - - - -  - - - - - - - - - - -  - - - - - - - - %
\lfoot{{\gray{\footnotesize Compilado: \today \;-\;  \currenttime}}} % texto izquierda del pie
\rfoot{Página \thepage}
% texto derecha del pie
\cfoot{} % texto central del pie
\renewcommand{\headrulewidth}{0.4pt} % grosor de la línea de la cabecera
%\renewcommand{\footrulewidth}{0.1pt} % grosor de la línea del pie
% ///////////////////////////////////////////////////////////////////////////// %
%\title{Foro }
%\author{Rafa S.F.}
%\date{\today}
% //////////////////////////////////////////////// %

\begin{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   Figura 2.1
\begin{figure}[h]
\begin{center}
\psset{unit=.6cm,linewidth=1pt,linecolor=black,nodesep=3pt,arrowscale=1.3,arrows=->,arrowsize=4pt}\small
 \begin{pspicture}*(-.5,0)(9.5,9.5)
\psframe[fillcolor=white,fillstyle=solid,linestyle=none](-.5,0)(9.5,9.5)

\rput(1,3){$\circlenode{A}{\textcolor{blue}{a}}$}
\rput(3,6){$\circlenode{B}{\textcolor{blue}{b}}$}
\rput(5,1){$\circlenode{C}{\textcolor{blue}{c}}$}
%
\ncline{->}{A}{B}\naput{\small $43$}
\ncarc[arcangleB=300]{->}{C}{B}\naput{\small $12$}
%
\ncarc{->}{C}{A}\naput{\small $23$}

%


 \end{pspicture}
\end{center}
\caption{prueba}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
share|improve this question
    
By design, jpeg doesn't support transparency. –  AlexG Jun 6 '13 at 10:43
    
@AlexG OK, you´re right, but PNG and GIF, yes. I know that GIF is a commercial format, so i prefer PNG. –  Mika Ike Jun 6 '13 at 10:51
    
Why should it be transparent? Without using the environment pspicture you can draw over any object. –  Herbert Jun 6 '13 at 14:51
    
@MikaIke: The patents on GIF are long expired; GIF is free. –  Martin Schröder Jun 6 '13 at 14:56
    
@Herbert: I guess he wants to use it in a web page, perhaps with a wall paper behind. –  AlexG Jun 6 '13 at 15:00

2 Answers 2

up vote 9 down vote accepted

Using ImageMagick:

convert -density 300x300 simplenetwork02_stack.pdf -transparent white simplenetwork02_stack.png

To have just the PSTricks graphic as output, add

\usepackage[tightpage,active]{preview}
\PreviewEnvironment{pspicture}

to the preamble. You may want to adjust the pspicture size to get a tightly boxed graphic:

\begin{pspicture}*(0,0)(6,7)
%\psframe[fillcolor=white,fillstyle=solid,linestyle=none](-.5,0)(7.5,7.5)

enter image description here

share|improve this answer
    
Perfect!! I like your solution. Where i shoul type -convert density..... I usually click the PDFLATEX/xelatex icon, and obtain de PDF. img854.imageshack.us/img854/4679/snap2163.png –  Mika Ike Jun 6 '13 at 19:31
1  
@MikaIke: ImageMagick is a separate piece of software (independend from TeX), consisting of a number of commandline tools. You can download it from imagemagick.org. convert is run on the ready PDF file that was output by xelatex or latex->dvips->ps2pdf. –  AlexG Jun 6 '13 at 19:53
    
\AlexG ok, i´m trying. –  Mika Ike Jun 7 '13 at 5:51
    
Thank you, I downloaded imagemagick, but I don´t have a visual compiler. I like your solution, and I don´t know to abuse but... ¿Do you know about any other software to do this? I´m trying to install imagemagick,.. (windows).. but seems dificult. –  Mika Ike Jun 7 '13 at 19:23
    
As I see that you control the situation :-) ... Any off-topic... I compile with Xelatex to can obtain the PSTricks picture, but it seems a little slow. What is the best option in your opinion? –  Mika Ike Jun 8 '13 at 7:08

By default the canvas provided by pspicture is transparent. If you fill it with other colors such as psframe[fillstyle=solid,fillcolor=white]... then the canvas is no longer transparent.

\documentclass[pstricks,border=12pt]{standalone}% set border=0pt if you don't want to have borders.
\begin{document}
\begin{pspicture}[showgrid=true](3,3)
    \pscircle(1.5,1.5){1}
\end{pspicture}
\end{document}

Compile the code above to get a PDF output. And then use ImageMagick to convert it to PNG with transparency as follows.

convert -density 100 -alpha on filename.pdf filename.png

The output is

enter image description here

The quote markdown is used here to show the transparency effect clearly. The background looks yellowish that proves that it is really transparent!

Remarks:

-alpha has 3 mutual-exclusive options: on (enabling transparency), off (disabling transparency with bad output), and remove (removing transparency with good output).

Warning:

The -transparent option explained and suggested by AlexG does not produce a good output as follows.

The following is the input. The red region will be converted to be transparent.

enter image description here

After conversion with convert -density 300 -transparent red in.pdf out.png, the output is as follows.

enter image description here

There are still red pixels on the boundaries of the red region. Are you satisfied with it? I don't.

share|improve this answer
    
I like your response. I downloaded ImageMagick, but It seems any ocmplicated. I have no Visual Studio to compile... and I haven´t benn capable to execute de "convert ...." command. Could you help me? –  Mika Ike Jun 8 '13 at 7:10
1  
@MikaIke: You should download the binary rather than the source code. I will give you the correct link to download the binary. Please wait in a couple of miliseconds. –  stalking is prohibited Jun 8 '13 at 7:14
1  
@MikaIke: It is the link to download the binary for Windows: imagemagick.org/script/binary-releases.php#windows –  stalking is prohibited Jun 8 '13 at 7:16
    
Yes... i prefer a clean boundarie. Thank you very much :-)) I´m impresed. Do you recomend me any web with fantastic scientifics graphs/wallpapers? –  Mika Ike Jun 8 '13 at 9:08
    
jajaja :-) please,... only 1 milisecond jajaja :-)))) –  Mika Ike Jun 8 '13 at 9:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.