Created
May 16, 2011 10:38
-
-
Save iley/974215 to your computer and use it in GitHub Desktop.
thumbnail.aspx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Import Namespace="System" %> | |
<%@ Import Namespace="System.IO" %> | |
<%@ Import Namespace="System.Web" %> | |
<%@ Import Namespace="System.Drawing" %> | |
<%@ Import Namespace="System.Drawing.Imaging" %> | |
<script language="C#" runat="server"> | |
public bool ThumbnailCallback() { | |
return false; | |
} | |
private void Page_Load(object sender, System.EventArgs e) { | |
int width = 600; | |
string imageFile = Request.PhysicalApplicationPath + "\\" + Request.QueryString["image"].ToString(); | |
string thumbFile = Path.GetDirectoryName(imageFile) + "\\" + | |
"thumb_" + | |
Path.ChangeExtension(Path.GetFileName(imageFile), ".jpg"); | |
System.Drawing.Image thumb; | |
if(!File.Exists(thumbFile) || | |
DateTime.Compare(File.GetLastWriteTime(imageFile), | |
File.GetLastWriteTime(thumbFile)) >= 0) { | |
System.Drawing.Image img = System.Drawing.Image.FromFile(imageFile); | |
int height = img.Height * width / img.Width; | |
thumb = img.GetThumbnailImage(width, height, ThumbnailCallback, IntPtr.Zero); | |
thumb.Save(thumbFile, ImageFormat.Jpeg); | |
} else { | |
thumb = System.Drawing.Image.FromFile(thumbFile); | |
} | |
thumb.Save(Response.OutputStream, ImageFormat.Jpeg); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment