\NeedsTeXFormat{LaTeX2e}[2020/10/01]
\ProvidesPackage{titleimage}[2024/03/08/ v0.1 Package for adding south-shading full width picture on the top of page.]

\RequirePackage{tikz,xcolor}
\usetikzlibrary{shadings}
\definecolor{titleline}{HTML}{006E54} %

\newsavebox\imagebox % goes into the preamble
\NewDocumentCommand{\titleimage}{ o m }{
    \tikz[remember picture,overlay]
    {
        \node[scope fading=south,anchor=north,inner sep=0pt,outer sep=auto] at (current page.north) {\includegraphics[width=\paperwidth]{#2}};
        \IfNoValueF{#1}{
            \fill [backgroundcolor!40,opacity=0.5] ($(current page.north west)-(0,3.5/13*\paperwidth)$) rectangle +(\paperwidth,-\paperwidth/13); % 中间
            \draw [line width=2pt,titleline!40] ($(current page.north west)-(0,3.5/13*\paperwidth)$) -- ($(current page.north east)-(0,3.5/13*\paperwidth)$); % 上线
            \draw [line width=2pt,titleline!40] ($(current page.north west)-(0,4.5/13*\paperwidth)$) -- ($(current page.north east)-(0,4.5/13*\paperwidth)$); % 下线
            \node at ($(current page.north west)-(-0.5*\paperwidth,4/13*\paperwidth)$) {#1};
        }
    }
}