TeX is text based, it cannot determine the size of PNG image itself by default.
A quick solution:
\usepackage{bmpsize}
And use
\usepackage[dvipdfmx]{graphicx}
It is better to use extractbb
(also named ebb
, xbb
) program to produce .bb
or .xbb
file for LaTeX. Use this command in 'Command Prompt':
for %i in (*.png) do xbb %i
(or for %i in (*.png) do extractbb -x %i
, I'm not sure about MiKTeX.)
And use
\usepackage[dvipdfmx]{graphicx}
(I use TeX Live, only dvipdfmx supports png images. But MiKTeX seems different, I can't remember well.)
The obvious problem is that the generated number is not 2 for the second image, as a simple
\showthe\pdflastximage
put just after
\pdfximage height 28.0mm {my_other_pic.png}
will show:
> 3.
l.18 \showthe\pdflastximage
This is probably due to the fact that one more picture object is included for "masking" the one with transparent background.
There is another primitive, \pdflastximage
that can (and should) be used for these situations: it is a read-only integer that is loaded with the number assigned to the last object included with \pdfximage
. However you can't say
\newcommand{\LOGOi}{\pdfrefximage\pdflastximage}
because this would always refer to the last image. Some lower level trickery is needed:
\pdfximage width 20.0mm height 8.0mm {png_transparent_bg.png}
\edef\LOGOi{\pdfrefximage\the\pdflastximage\relax}
\pdfximage height 28.0mm {my_other_pic.png}
\edef\LOGOii{\pdfrefximage\the\pdflastximage\relax}
\pdfximage height 20.0mm {my_cool_pic.png}
\edef\LOGOiii{\pdfrefximage\the\pdflastximage\relax}
Each \edef
will expand \the\pdflastximage
to the current value; in your case, the expansions of \LOGOi
, \LOGOii
and \LOGOiii
will be
> \LOGOi=macro:
->\pdfrefximage 1\relax .
> \LOGOii=macro:
->\pdfrefximage 3\relax .
> \LOGOiii=macro:
->\pdfrefximage 4\relax .
as required for a correct later usage of the images.
It's quite unclear why you don't want to use the higher level \includegraphics
for this. If you're afraid that multiply used pictures are included multiple times in the PDF file, don't be.
In case you've inherited some document where these low level tricks are used, just comment out the lines and change them according to this model
%\pdfximage width 20.0mm height 8.0mm {png_transparent_bg.png}
%\edef\LOGOi{\pdfrefximage\the\pdflastximage\relax}
%\pdfximage height 28.0mm {my_other_pic.png}
%\edef\LOGOii{\pdfrefximage\the\pdflastximage\relax}
%\pdfximage height 20.0mm {my_cool_pic.png}
%\edef\LOGOiii{\pdfrefximage\the\pdflastximage\relax}
\usepackage{graphicx}
\newcommand\LOGOi{\includegraphics[width 20.0mm, height 8.0mm]{png_transparent_bg.png}}
\newcommand{\LOGOii}{\includegraphics[height 28.0mm]{my_other_pic.png}}
\newcommand{\LOGOiii}{\includegraphics[height 20.0mm]{my_cool_pic.png}}
Best Answer
Update at the end -- give it a try
The background image can be done with
tcolorbox
and using many of its options, putting it in the background. See the applications of the options how the image is changed.Considering the dimensions: Please take into account the cutting by your printer, so the margins should be larger, most likely!