System.Collections.Specialized.NameValueCollection req= Request.QueryString;
//get height
string h=req["h"];
//get width
string w = req["w"];
// get text
string t = req["t"];
if (t == null || t.Length == 0)
throw new HttpException("QueryString t not supplied");
int hashCode = t.GetHashCode();
string checkEtag = Request.Headers["ETag"];
if (checkEtag != null && checkEtag.Length != 0)
{
if (checkEtag == hashCode.ToString())
{
Response.StatusCode = (int)System.Net.HttpStatusCode.NotModified;
Response.StatusDescription = "Not modified";
Response.SuppressContent = true;
return;
}
}
req= System.Web.Configuration.WebConfigurationManager.AppSettings;
string colrRadiantStart = req["btnBgRadiantStart"];
string fontSize = req["btnFontSize"];
string FontName = req["btnFontName"];
string colrRadiantEnd = req["btnBgRadiantEnd"];
string FontColor = req["btnFontColor"];
System.Drawing.Color ocolorEnd, colorStart, colorFont ;
if (colrRadiantStart != null && colrRadiantStart.Length == 6)
colorStart = parsRgb(colrRadiantStart);
else
throw new HttpException("You must provide a valid btnBgColor hex rgb-code in appConfig");
if (colrRadiantEnd == null || colrRadiantEnd.Length != 6)
throw new HttpException("You must provide a valid btnBgColor hex rgb-code in appConfig");
else
ocolorEnd = parsRgb(colrRadiantEnd);
if (FontColor == null || FontColor.Length != 6)
colorFont = Color.Black; //default
else
colorFont = parsRgb(FontColor);
int iH = int.Parse(h);
int iW = int.Parse(w);
Bitmap oBmp1 = new Bitmap(iW, iH);
Graphics oGrp1 = Graphics.FromImage(oBmp1);
// seems not to have effect
oGrp1.CompositingQuality = CompositingQuality.HighQuality;
oGrp1.InterpolationMode = InterpolationMode.HighQualityBilinear;
LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0, 0, iW, iH), colorStart, ocolorEnd, LinearGradientMode.Vertical);
oGrp1.FillRectangle(lgb, 0, 0, iW, iH);
System.Drawing.FontFamily fntFam = new FontFamily(FontName);
Font fnt = new Font(fntFam, float.Parse(fontSize));
StringFormat stringFormat = StringFormat.GenericDefault;
//we must set this value, other wise text will default to left.
stringFormat.Alignment = StringAlignment.Center;
SizeF szf = oGrp1.MeasureString(t, fnt, new SizeF(iW, iH), stringFormat);
//center
PointF FPoint = new PointF((iW - szf.Width) / 2, (iH - szf.Height) / 2);
oGrp1.DrawString(t, fnt, new SolidBrush(colorFont), new RectangleF(FPoint.X, FPoint.Y, szf.Width, szf.Height), stringFormat);
Response.ContentType = "image/jpeg";
Response.Cache.SetETag(hashCode.ToString());
//Response.Cache.SetLastModified(DateTime.Now);
Response.Cache.SetCacheability(HttpCacheability.Public);
oBmp1.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.End();