% Fading text
% Author: Elke Schubert
\documentclass[border=10pt,varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\tikzset{fading text/.style={}}

\newcommand\fadingtext[2][]{%
  \begin{tikzfadingfrompicture}[name = fading letter]
    \node[text = transparent!0, inner xsep = 0pt, outer xsep = 0pt] {#2};
  \end{tikzfadingfrompicture}%
  \begin{tikzpicture}[baseline = (textnode.base)]
    \node[inner sep = 0pt, outer sep = 0pt] (textnode) {\phantom{#2}}; 
    \shade[path fading = fading letter, fading text, #1, fit fading = false]
    (textnode.south west) rectangle (textnode.north east);% 
  \end{tikzpicture}% 
}

\usepackage{lipsum}
\begin{document}
\tikzset{fading text/.style = {left color = red, right color = red!50!blue,
  middle color = green}}
\setlength\fboxsep{0pt}
\fbox{\scalebox{4}{\fadingtext[left color = green, right color = red]{$4$}}}
For testing the alignment: \fadingtext{Here is a colored sample sentence.} 

\noindent\fadingtext[top color = orange, bottom color = purple,
  middle color=.]{\parbox[b]{\linewidth}{\strut\lipsum[1]}}
\end{document}
