6

I am using the qrcode package and I know how to make plain colored qr codes:

\usepackage{qrcode}[]

\color{blue}{\qrcode[height=7cm]{site qr code}}

but I want to make with gradient colors, How to do this? This is what I want:

enter image description here

  • If I were you I'd generate the QR code and use Gimp or another image editing software for something like this. If you insist on doing this within latex then here are a few starting pointers: 1. The package uses simple \rule to generate the white and black squares in the matrix (see line 891 in the .dtx file) 2. You could use etoolbox package to edit the relevant lines and replace the rule with a tikzrule. 3. The tikzrule gradient would have to depend on the line of the square in the matrix. – Elad Den Aug 30 '20 at 07:20

1 Answers1

6

You can use the solution from here and use the qr code command instead of text as input for the newly created fadingtext command

\documentclass{article} 
\usepackage{qrcode}[]
\usepackage{tikz}
\usetikzlibrary{fadings, shadings}
\newcounter{fadcnt}\setcounter{fadcnt}{0}
\newcommand\fadingtext[3][]{%
\stepcounter{fadcnt}
  \begin{tikzfadingfrompicture}[name=fading letter\thefadcnt]
    \node[text=transparent!0,inner xsep=0pt,outer xsep=0pt,#1] {#3};
  \end{tikzfadingfrompicture}%
  \begin{tikzpicture}[baseline=(textnode.base)]
    \node[inner sep=0pt,outer sep=0pt,#1](textnode){\phantom{#3}}; 
    \shade[path fading=fading letter\thefadcnt,#2,fit fading=false]
    (textnode.south west) rectangle (textnode.north east);% 
  \end{tikzpicture}% 
}
\usetikzlibrary{calc}
\newbox\shbox
\tikzset{%
  path picture shading/.style={%
  path picture={%
%
\pgfpointdiff{\pgfpointanchor{path picture bounding box}{south west}}%
  {\pgfpointanchor{path picture bounding box}{north east}}%
\pgfgetlastxy\pathwidth\pathheight%
\pgfinterruptpicture%
   \global\setbox\shbox=\hbox{\pgfuseshading{#1}}%
 \endpgfinterruptpicture%
\pgftransformshift{\pgfpointanchor{path picture bounding box}{center}}%
\pgftransformxscale{\pathwidth/(\wd\shbox)}%
\pgftransformyscale{\pathheight/(\ht\shbox)}% \dp will (should) be 0pt
\pgftext{\box\shbox}%
%
    }
  }
}
\pgfdeclarehorizontalshading{rainbow}{10bp}{color(0bp)=(violet);
            color(1.6667bp)=(blue);
            color(3.3333bp)=(cyan);
            color(5bp)=(green);
            color(6.6667bp)=(yellow);
            color(8.3333bp)=(orange);
            color(10bp)=(red)}
\pgfdeclareverticalshading{rainbow_vertical}{10bp}{color(0bp)=(violet);
            color(1.6667bp)=(blue);
            color(3.3333bp)=(cyan);
            color(5bp)=(green);
            color(6.6667bp)=(yellow);
            color(8.3333bp)=(orange);
            color(10bp)=(red)}
\begin{document} 
\noindent
\fadingtext[scale=1]{upper left=red, upper right=green, lower left=blue,lower right=yellow}{\qrcode[height=5cm]{site qr code}}
\fadingtext[scale=1]{path picture shading=rainbow}{\qrcode[height=5cm]{site qr code}}
\fadingtext[scale=1]{path picture shading=rainbow_vertical}{\qrcode[height=5cm]{site qr code}}
\end{document}

Output