如何在LaTex中製作漸層色的二維碼?

如何在LaTex中製作漸層色的二維碼?

我正在使用 qrcode 包,並且我知道如何製作純色 qr 尺寸:

\usepackage{qrcode}[]

\color{藍色}{\qrcode[height=7cm]{網站二維碼}}}

但我想用漸層顏色製作,該怎麼做?這就是我要的:

在此輸入影像描述

答案1

您可以使用以下解決方案這裡並使用二維碼命令而不是文字作為新創建fadingtext命令的輸入

\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}

輸出

相關內容