How can I generate in xelatex a QR code with any given image inside, like so or better like this, using either pstricks or the new qrcode package? Note that the QR-code must still work after including the image.

1 Answer 1


Follows a proposal using tikz. For the code to properly compile, the image to embed (named "image.jpg" in this code) must be present, like this one:

image to embed

The result is given by:

QR code with and embedded image

The code to produce this result is the following:


% Program to draw a QR code and insert an image in
% its center without disrupting the contents
% v.santos, 2020


% Fraction of QR code width to replace
% Maximal value depends on the level of robustness of QR code
\def\wFrac{0.33}%   % 0.3 is usually OK for M (sometimes can go up to 0.4 for H)

% Dimension registers to use later

% The actual desired size of the QR code in the page (should not affect the result)

% define the text to embed (can change the level
% of robustness with option "level")
% The qrcode package requires some chars to be escaped (like space)
My\ QR\ code\ with\ an\ image\ in\ it.

\fbox{% % to put a frame around the QR code
\node [anchor=south west,inner sep=0] at (0,0) (QR) {\myQR};
\begin{scope}[x={(QR.south east)},y={(QR.north west)}]
    \node [inner sep=0,anchor=south west] at (0.5-\wFrac/2,0.5-\wFrac/2) {\includegraphics[width=\imWidth,height=\imWidth]{image.jpg}};


You must log in to answer this question.

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