5

Maybe this is more appropriate for meta, but I'll try it here first (please move if inappropriate).

I have noticed for a while now that @egreg has some very decent screenshots of examples; for instance, on Positioning includegraphics vertically on a line?, for the MWE:

\documentclass{article}
\usepackage{graphicx}

\begin{document}

Just testing something here... Lorem ipsum dolor sit amet,...

\noindent%
Attempt at signature:
\makebox[0pt][l]{\hspace*{2cm}\raisebox{-3ex}{\includegraphics{testing.png}}}%
\hrulefill

That's all, folks ...
\end{document}

... I, using ImageMagick's convert from the command line:

convert -density 300 -resample 150 test.pdf test.png

..., obtain something like this:

test.png

...; while @egreg obtains something like this:

etest.png

... where the fonts look a lot better.

Maybe it has to do with @egreg's original image being 1990x452 pixels, while mine was 776x183 pixels - but in this post I've scaled his image down (cubic) to approximately the same resolution as mine, and it still looks better.

I'm assuming we're both just using pdflatex test.tex to compile the MWE, so it should be the same PDF; how is this nice(r) rasterization then obtained? Is it just rasterizing at greater resolutions at first - or is it down to the rasterizing tool(chain)?

4
  • Try saving yours at the exact same resolution as his, then scaling them to the same: Downscaling images can make them look smoother and nicer then rendering them at the final resolution. Does that improve how yours looks? The other thing I can think of (No time to test it now) is that he is using the 'minimal' document class with some of his and directly saving it as png. You could go into chat and ask him.
    – Canageek
    May 10, 2015 at 0:56
  • I don't know, but I think that's just a screen print on a high resolution display. I get “similar quality” (without putting too much eye into it) in my non resolution display (obviously smaller in size).
    – Manuel
    May 10, 2015 at 1:27
  • @Canageek I think the standalone class might be better suited ;-)
    – Johannes_B
    May 10, 2015 at 7:16
  • 3
    I just take a screen snapshot; the high quality is ensured by a Retina display.
    – egreg
    May 10, 2015 at 8:42

1 Answer 1

1

I use a bash script for conversion. You could adjust the resolution up from 120 to get a crisper result. I use 120 just to keep the file size minimal.

It crops to content, so if I'm using the article class I usually add a \pagestyle{empty} so it crops down to just the page content, rather than including the page number.

#!/bin/bash

# usage: pdf2tsxpng <file.pdf>

PDF=$1
BASE=`basename $1 .pdf`
CROPPEDPDF="$PDF-crop.pdf"
PNG="$BASE.png"
RGBPROFILE="/usr/share/color/icc/sRGB2014.icc"
CMYKPROFILE="/usr/share/color/icc/ISOcoated_v2_300_eci.icc"
RESOLUTION=120

PDFCROP=/usr/bin/pdfcrop

GS=/usr/bin/gs
GSOPTS="-dSAFER -dNOPAUSE -dBATCH -sOutputFile=$PNG -sDEVICE=png16m -r$RESOLUTION -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDefaultRGBProfile=$RGBPROFILE -sDefaultCMYKProfile=$CMYKPROFILE -sOutputICCProfile=$RGBPROFILE"

MOGRIFY=/usr/bin/mogrify
MOGRIFYOPTS="-strip"

echo "Converting to TSX PNG..."
$PDFCROP $PDF $CROPPEDPDF > /dev/null
$GS $GSOPTS $CROPPEDPDF > /dev/null
$MOGRIFY $MOGRIFYOPTS $PNG
rm -f $CROPPEDPDF
2
  • Great, really usefull! But unfortunately the Adobe ICC profiles have spaces in the path. Your script doesn't work with spaces in the path. Would you mind to change that, if possible? Since I'm too dumb to find out how to adapt the $CMYKPROFILE to that, I made a symbolic link, e.g. ln -s ./Adobe\ ICC\ Profiles/CMYK\ Profiles/EuropeISOCoatedFOGRA27.icc EuropeISOCoatedFOGRA27.icc . But otherwise, very good help!
    – Keks Dose
    Feb 14, 2018 at 17:58
  • Yeah, it's not safe for wider usage and there's no error checking. But you could easily fix those issues to suit your own purposes. Feb 15, 2018 at 10:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .