-
Notifications
You must be signed in to change notification settings - Fork 15
/
NBrightThumb.ashx.cs
78 lines (65 loc) · 2.65 KB
/
NBrightThumb.ashx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Web;
using NBrightCore.common;
using NBrightCore.images;
namespace Nevoweb.DNN.NBrightBuy
{
/// <summary>
/// Summary description for NBrightThumb1
/// </summary>
public class NBrightThumb : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
var w = Utils.RequestQueryStringParam(context, "w");
var h = Utils.RequestQueryStringParam(context, "h");
var src = Utils.RequestQueryStringParam(context, "src");
var imgtype = Utils.RequestQueryStringParam(context, "imgtype");
if (h == "") h = "0";
if (w == "") w = "0";
if (Utils.IsNumeric(w) && Utils.IsNumeric(h))
{
src = HttpContext.Current.Server.MapPath(src);
var strCacheKey = context.Request.Url.Host.ToLower() + "*" + src + "*" + Utils.GetCurrentCulture() + "*img:" + w + "*" + h + "*";
var newImage = (Bitmap) Utils.GetCache(strCacheKey);
if (newImage == null)
{
newImage = ImgUtils.CreateThumbnail(src, Convert.ToInt32(w), Convert.ToInt32(h));
Utils.SetCache(strCacheKey, newImage);
}
if ((newImage != null))
{
ImageCodecInfo useEncoder;
// due to issues on some servers not outputing the png format correctly from the thumbnailer.
// this thumbnailer will always output jpg, unless specifically told to do a png format.
useEncoder = ImgUtils.GetEncoder(ImageFormat.Jpeg);
if (imgtype.ToLower() == "png") useEncoder = ImgUtils.GetEncoder(ImageFormat.Png);
var encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 85L);
try
{
newImage.Save(context.Response.OutputStream, useEncoder, encoderParameters);
}
catch (Exception exc)
{
var outArray = Utils.StrToByteArray(exc.ToString());
context.Response.OutputStream.Write(outArray, 0, outArray.Count());
}
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}