|
| image: http://secretgeek.net/Gradient.aspx?Direction=H&Length=100&StartColor=00FFFF&EndColor=00FF00&Format=jpeg |
| image: http://secretgeek.net/Gradient.aspx?Direction=H&Length=100&StartColor=FF0000&EndColor=000000&Format=jpeg |
| image: http://secretgeek.net/Gradient.aspx?Direction=H&Length=100&StartColor=FFFF00&EndColor=000000&Format=jpeg |
| image: http://secretgeek.net/Gradient.aspx?Direction=V&Length=300&StartColor=0088FF&EndColor=FFFFFF&Format=jpeg |
| image: http://secretgeek.net/Gradient.aspx?Direction=V&Length=100&StartColor=FFFFFF&EndColor=0088FF&Format=jpeg |
| image: http://secretgeek.net/Gradient.aspx?Direction=H&Length=100&StartColor=FF0000&EndColor=FF8800&Format=jpeg |
| Parameter | Description |
|---|---|
| Direction | V for vertical or H for horizontal. Not sure which is which... |
| Length | How long should the image be? It will always have a breadth of 1-pixel. (Whether Length refers to height or width, depends on whether the image is vertical or horizontal!) |
| StartColor | The rgb value of the Starting color, excluding the '#' character. |
| EndColor | The rgb value of the Final color, excluding the '#' character. |
| Format | Jpeg, Gif or Png? |
If parameters are wrongly setup, or if something else goes wrong, you get an image like this one:
Imports System.Drawing
Imports System.Drawing.Drawing2D
...
Private Sub
Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Handles MyBase.Load
'Put user code to
initialize the page here
Dim sMessage As String
Try
'Parameters:
Dim
_Direction As String
'Horizontal or Vertical
Dim
_Length As Long
Dim _StartColor As String
Dim _EndColor As String
Dim
_Format As String
sMessage
= "retrieving parameters"
_Direction = Request.QueryString.Item("Direction")
_Length = Request.QueryString.Item("Length")
_StartColor =
Request.QueryString.Item("StartColor")
_EndColor = Request.QueryString.Item("EndColor")
_Format = Request.QueryString.Item("Format")
Dim lWidth As Integer
Dim lHeight As Integer
Dim
m_Color1 As Color
Dim
m_Color2 As Color
Dim myFormat As System.Drawing.Imaging.ImageFormat
Dim myGradientMode As LinearGradientMode
sMessage
= "processing parameters"
'Now use the
parameters
If _Direction.ToUpper.StartsWith("H") Then
lWidth = 1
lHeight = _Length
myGradientMode
= LinearGradientMode.Vertical
Else
lWidth = _Length
lHeight = 1
myGradientMode = LinearGradientMode.Horizontal
End If
If _Format.ToUpper.StartsWith("J") Then
myFormat = Imaging.ImageFormat.Jpeg
Else
myFormat = Imaging.ImageFormat.Gif
End If
sMessage
= "determining colors"
m_Color1 = Color.FromArgb(255, _
CLng("&H" & _StartColor.Substring(0,
2)), _
CLng("&H" & _StartColor.Substring(2,
2)), _
CLng("&H" & _StartColor.Substring(4,
2)))
m_Color2 = Color.FromArgb(255, _
CLng("&H" & _EndColor.Substring(0,
2)), _
CLng("&H" & _EndColor.Substring(2,
2)), _
CLng("&H" & _EndColor.Substring(4,
2)))
'GO!
sMessage = "determining
size"
Dim bmpGradient As New Bitmap(lWidth, lHeight)
Dim m_BrushSize As New Rectangle(0, 0, lWidth, lHeight)
Dim grBitmap As Graphics = Graphics.FromImage(bmpGradient)
sMessage
= "creating gradient brush"
Dim myLinearGradientBrush As New LinearGradientBrush( _
m_BrushSize,
m_Color1, m_Color2, _
myGradientMode)
sMessage
= "filling rectangle"
grBitmap.FillRectangle(myLinearGradientBrush, 0, 0, _
lWidth, lHeight)
sMessage = "saving image to
response stream"
'Write the image to the client!!
bmpGradient.Save(Response.OutputStream, myFormat)
Catch ex As System.Exception
Dim bmpGradient As New Bitmap(600, 100)
Dim m_BrushSize As New Rectangle(0, 0, 600, 100)
Dim grBitmap As Graphics = Graphics.FromImage(bmpGradient)
Dim myLinearGradientBrush As New LinearGradientBrush( _
m_BrushSize,
_
Color.FromArgb(255, 255, 0, 0), _
Color.FromArgb(255, 0, 0, 0), _
LinearGradientMode.Vertical)
grBitmap.FillRectangle(myLinearGradientBrush, 0, 0, _
600, 100)
grBitmap.DrawString("Error while " & _
sMessage & " for '" & Request.UserHostAddress & _
"'." & vbCrLf & ex.Message, _
New System.Drawing.Font("Arial", 12, _
System.Drawing.FontStyle.Italic),
_
System.Drawing.Brushes.White,
10, 12)
'Write the error message image to the client
bmpGradient.Save(Response.OutputStream, _
System.Drawing.Imaging.ImageFormat.Jpeg)
End Try
End Sub
'Tobias' on Fri, 05 Aug 2005 12:08:52 GMT, sez:
Once in a while I come across articles which make me go "Why on earth didn't I think of this ages ago". This is definitely one of them. I'm using gradients everywhere in my web designs - this is going to save me a ton of Photoshop work. Thanks a lot for the idea!
'blameMike' on Fri, 05 Aug 2005 17:32:15 GMT, sez:
Dude... you're my hero.
All kidding aside, that's awesome. Of course I noticed the cool gradient in IE, but none in Firefox. I didn't want to say anything though, as I already bitched about the button. ;)
'adam adobe' on Sat, 06 Aug 2005 09:14:13 GMT, sez:
On behalf of Adobe Photoshop, we insist you take down this webservice.
This is a blatant attempt to put us out of work.
'Tao' on Tue, 09 Aug 2005 02:29:20 GMT, sez:
Well done!
Now I only have a small question:
if you have a look the IE Gradient Filter example:
http://msdn.microsoft.com/workshop/samples/author/filter/gradient.htm
There has two alpha value from 00 to FF on StartColor and EndColor. Can the Color Gradient Webservice support this value too?
'leon' on Tue, 09 Aug 2005 04:05:01 GMT, sez:
sorry Tao -- I hardcode in 255 (i.e. FF) for the alpha value.
'Profx' on Fri, 07 Oct 2005 20:57:46 GMT, sez:
<img src='http://secretgeek.net/Gradient.aspx?Direction=H&Length=150&StartColor=FF00FF&EndColor=00FF00&Format=jpeg'>
'Profx2' on Fri, 07 Oct 2005 21:05:49 GMT, sez:
<TD id=msviRegionGradient1
style="FILTER: progid:DXImageTransform.Profx.Gradient(startColorStr='#4B92D9', endColorStr='#CEDFF6', gradientType='1')"
width="50%"></TD>
'http://' on Fri, 07 Oct 2005 21:07:38 GMT, sez:
FILTER: progid:DXImageTransform.Profx.Gradient(startColorStr='#4B92D9', endColorStr='#CEDFF6', gradientType='1')"
'Microsoft' on Fri, 07 Oct 2005 21:43:48 GMT, sez:
<SCRIPT language=JavaScript>
<!--
function view(){
document.all.item('gra1').filters['DXImageTransform.Microsoft.Gradient'].Enabled=1;
}
function unview(){
document.all.item('gra1').filters['DXImageTransform.Microsoft.Gradient'].Enabled=0;
}
function tate(){
document.all.item('gra1').filters['DXImageTransform.Microsoft.Gradient'].GradientType=0;
}
function yoko(){
document.all.item('gra1').filters['DXImageTransform.Microsoft.Gradient'].GradientType=1;
}
//-->
</SCRIPT>
<DIV id=gra1
style="FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=1,StartColorStr=#0000ffff,EndColorStr=#ff000099); WIDTH: 100%; HEIGHT: 100%"><BR><BR>
'Microsoft' on Wed, 12 Oct 2005 12:52:35 GMT, sez:
<style type="text/css">
.grad {
filter: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=yellow,endColorStr=Green);
width: 1010px;
height: 400px;
}
</style>
and
<body class="grad">
'Esempio Corporation' on Mon, 28 Nov 2005 10:57:50 GMT, sez:
<style type="text/css">
<!--
#subheader { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; BACKGROUND: url(http://www.esempio.it/Esempio_Filter.jpg) #00CC66 repeat-x left top; PADDING-BOTTOM: 3px; PADDING-TOP: 4px; BORDER-BOTTOM: #f0f0f2 1px solid}
-->
</style>
Questo Metodo semplifica la soluzione Filter che consente di usare di qualche tabella di Modificare alcune cose (Dell'Esempio Pratico della Filter si ottiene così):
<DIV id=subheader>
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr valign="bottom">
<td><a href="http://www.esempio.it/*">Gestisci
il tuo profilo</a> |<a
href="http://www.esempio.it/*"
target="_parent">Contattaci</a></div>
<div><span>©2005 Esempio Corporation. Tutti
i diritti sono riservati. </span><a
href="http://www.esempio.it/*" target="_parent">Note
legali</a> |<a
href="http://www.esempio.it/*">Marchi</a> |<a href="http://www.esempio.it/*"
target="_parent">Informativa sulla privacy</a></div></td>
</tr>
</tbody>
</table>
</DIV>
<table height="58" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr valign="top">
<td><div style="WIDTH: 200px"></div></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</body>
</html>
'Esempio Corporation' on Mon, 28 Nov 2005 11:06:10 GMT, sez:
<style type="text/css">
<!--
#subheader { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; BACKGROUND: url(http://www.esempio.it/Esempio_Filter.jpg) #00CC66 repeat-x left top; PADDING-BOTTOM: 3px; PADDING-TOP: 4px; BORDER-BOTTOM: #f0f0f2 1px solid}
-->
</style>
Autorizzo di modifcare questo indirizzo url(http://www.esempio.it/Esempio_Filter.jpg) e poi modificare i colori # che scegliete i colori desiderati che vi piaciono a tutti gli utenti(Un Utente o qualunque utente).
<DIV id=subheader>
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr valign="bottom">
<td><a href="http://www.esempio.it/*">Gestisci
il tuo profilo</a> |<a
href="http://www.esempio.it/*"
target="_parent">Contattaci</a>
<div><span>©2005 Esempio Corporation. Tutti
i diritti sono riservati. </span><a
href="http://www.esempio.it/*" target="_parent">Note
legali</a> |<a
href="http://www.esempio.it/*">Marchi</a> |<a href="http://www.esempio.it/*"
target="_parent">Informativa sulla privacy</a></div></td>
</tr>
</tbody>
</table>
</DIV>
<table height="58" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr valign="top">
<td><div style="WIDTH: 200px"></div></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</body>
</html>
E impostate il vostro copyright del vostro sito personalizzato ho dato il toolkit per personalizzare la filter aggiungendo con .jpg e in più i colori personalizzati per ottenere la filter senza che venga salvato la foto jpg. Ti garantisco che la tecnologia funziona perfettamente perchè io lo ho provato e va benissimo. (Provare per credere).
'konq user' on Sun, 04 Jun 2006 07:37:08 GMT, sez:
All this stuff works in Konqueror, the KDE web browser. Thought I'd let you know.
'Thomas Frank' on Fri, 21 Jul 2006 05:02:17 GMT, sez:
Cool work!
Now if you want gradients in your headlines/text too, here's a solution for you:
http://www.thomasfrank.se/text_color_gradients.html
'Eddy' on Mon, 28 Aug 2006 06:31:56 GMT, sez:
Hi,
Is this open source ?, would it be o.k for me to use on a none profit making site ?
'Eddy' on Mon, 28 Aug 2006 08:48:43 GMT, sez:
here's another site with a similar project that
has a third gradient type http://tools.dynamicdrive.com/gradient/ they're not showing their source code though.
'lb' on Mon, 28 Aug 2006 21:21:25 GMT, sez:
Hi eddy -- yep i am willing to send you the source. I will also publish the source in full when i get around it.
meanwhile lots of people have been using this directly -- so i've justed updated it to stop it working temporarily.
see, for example: http://z9.invisionfree.com/R_I_P_2/index.php
I'm flattered that these guys are using my stuff... but i wish they'd do it legitimately!
my favourite is http://www.kargro.org/ -- if only there was an email provided i'd write to him and her, thank him and give him the source!
'Eddy' on Tue, 29 Aug 2006 16:46:21 GMT, sez:
I'm puzzled as to why someone would use your site to show a static gradient on their own site, I mean, how hard is it to save an image of about 1kb in size to the server ?.
If you ban their I.P to that gradient aspx page I'm sure they'll come back to the source and find your post, in anycase, thanks for your offer, I could really use something like this in the future to dynamically create several gradients per session (ideally as a server-side dll).
If you could send the source to pen.email(at)gmail.com I'd really appreciate that, thanks again.
'WPKF' on Tue, 21 Nov 2006 01:57:22 GMT, sez:
Interesting idea.
'Jeff' on Sat, 24 Mar 2007 23:05:07 GMT, sez:
Wow, you are one of the coolest programmers ever. Absolutely brilliant, I love it!
'Stephen' on Wed, 25 Jul 2007 19:10:54 GMT, sez:
I reworked this example into C#, added PNG, Transparency, Diagonal Gradients, and Bell Curve w/Scale and Focus.
Enjoy....
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
public partial class Gradient : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
string sMessage = "";
try
{
// Parameters:
string _Direction;
// Horizontal or Vertical
string _Height;
string _Width;
string _StartColor;
string _EndColor;
string _Format;
string _Focus;
String _Scale;
sMessage = "retrieving parameters";
_Direction = Request.QueryString["Direction"];
_Height = Request.QueryString["Height"];
_Width = Request.QueryString["Width"];
_StartColor = Request.QueryString["StartColor"];
_EndColor = Request.QueryString["EndColor"];
_Format = Request.QueryString["Format"];
_Focus = Request.QueryString["Focus"];
_Scale = Request.QueryString["Scale"];
float m_Focus = (float)Convert.ToDecimal(_Focus);
float m_Scale = (float)Convert.ToDecimal(_Scale);
int lWidth = Convert.ToInt32(_Width);
int lHeight = Convert.ToInt32(_Height);
Color m_Color1;
Color m_Color2;
System.Drawing.Imaging.ImageFormat myFormat;
LinearGradientMode myGradientMode;
sMessage = "processing parameters";
if (_Direction.ToUpper().StartsWith("V"))
{
myGradientMode = LinearGradientMode.Vertical;
}
else if (_Direction.ToUpper().StartsWith("H"))
{
myGradientMode = LinearGradientMode.Horizontal;
}
else if (_Direction.ToUpper().StartsWith("L"))
{
myGradientMode = LinearGradientMode.BackwardDiagonal;
}
else
{
myGradientMode = LinearGradientMode.ForwardDiagonal;
}
if (_Format.ToUpper().StartsWith("J"))
{
myFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
}
else if (_Format.ToUpper().StartsWith("G"))
{
myFormat = System.Drawing.Imaging.ImageFormat.Gif;
}
else
{
myFormat = System.Drawing.Imaging.ImageFormat.Png;
}
sMessage = "determining colors";
if (_StartColor.ToUpper().StartsWith("T"))
{
m_Color1 = Color.Transparent;
}
else
{
m_Color1 = Color.FromArgb(
int.Parse((_StartColor.Substring(0, 2)), System.Globalization.NumberStyles.HexNumber),
int.Parse((_StartColor.Substring(2, 2)), System.Globalization.NumberStyles.HexNumber),
int.Parse((_StartColor.Substring(4, 2)), System.Globalization.NumberStyles.HexNumber));
}
if (_EndColor.ToUpper().StartsWith("T"))
{
m_Color2 = Color.Transparent;
}
else
{
m_Color2 = Color.FromArgb(
int.Parse((_EndColor.Substring(0, 2)), System.Globalization.NumberStyles.HexNumber),
int.Parse((_EndColor.Substring(2, 2)), System.Globalization.NumberStyles.HexNumber),
int.Parse((_EndColor.Substring(4, 2)), System.Globalization.NumberStyles.HexNumber));
}
// GO!
sMessage = "determining size";
Bitmap bmpGradient = new Bitmap(lWidth, lHeight);
Rectangle m_BrushSize = new Rectangle(0, 0, lWidth, lHeight);
Graphics grBitmap = Graphics.FromImage(bmpGradient);
sMessage = "creating gradient brush";
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(m_BrushSize, m_Color1, m_Color2, myGradientMode);
if ((m_Focus>0) || (m_Scale>0))
{
myLinearGradientBrush.SetSigmaBellShape(m_Focus, m_Scale);
}
sMessage = "filling rectangle";
grBitmap.FillRectangle(myLinearGradientBrush, 0, 0, lWidth, lHeight);
sMessage = "saving image to response stream";
MemoryStream io = new MemoryStream();
bmpGradient.Save(io, myFormat);
Response.BinaryWrite(io.GetBuffer());
}
catch (System.Exception ex)
{
Bitmap bmpGradient = new Bitmap(600, 100);
Rectangle m_BrushSize = new Rectangle(0, 0, 600, 100);
Graphics grBitmap = Graphics.FromImage(bmpGradient);
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(m_BrushSize, Color.FromArgb(255, 255, 0, 0), Color.FromArgb(255, 0, 0, 0), LinearGradientMode.Vertical);
grBitmap.FillRectangle(myLinearGradientBrush, 0, 0, 600, 100);
grBitmap.DrawString("ERROR", new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Italic), System.Drawing.Brushes.White, 10, 12);
}
}
}
Add your comment.
Just Wally
The Correct Order for a First Time Viewing of The Lord Of The Rings
A new era for Android.
Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion
Got CSV in your javascript? Use agnes.
Complete secretGeek Archives
TimeSnapper: automatic screenshot journal
NimbleText: Code Generator, Text Manipulator, Data Extractor
25 steps for building a Micro-ISV
3 Minute Guide Series
Universal Troubleshooting Checklist
Top 10 SecretGeek articles
ShinyPower
RealTime Online CSS Editor
Gradient Maker
How to be depressed
You are not inadequate.
The Best Software Writing I
The Business Of Software (Eric Sink)
Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
Thomas White
OJ Reeves
Eric Sink
proggit
dzone
hacker news
dot net kicks
interesting finds
a continuous learner's weblog
arjan's world
weekly link post
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
PhysioTec, Brisbane Specialist Physiotherapy & Pilates