A thumbnail conversion script



I found a script that converts a regular size image to a thumbnail. It's a
wonderful script, except the thumbnail quality is a bit low.

I'd like to add the following code to improve the output quality of the
thumbnail. Can someone direct me where to incorporate this code? Thanks.

Code to insert:

graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphic.SmoothingMode = SmoothingMode.HighQuality;
graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphic.CompositingQuality = CompositingQuality.HighQuality;


Original script:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1"
%>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
try{
Response.Cache.VaryByParams["Image;Width;Height;ForceAspect"] = true;
Response.ContentType = "image/jpeg";
System.Collections.Hashtable imageOutputFormatsTable = new
System.Collections.Hashtable();
imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Gif.Guid,
System.Drawing.Imaging.ImageFormat.Gif);
imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Jpeg.Guid,
System.Drawing.Imaging.ImageFormat.Jpeg);
imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Bmp.Guid,
System.Drawing.Imaging.ImageFormat.Gif);
imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Tiff.Guid,
System.Drawing.Imaging.ImageFormat.Jpeg);
imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Png.Guid,
System.Drawing.Imaging.ImageFormat.Jpeg);

string imageLocation;
bool forceaspect = true;
int newHeight;
int newWidth;
int reqHeight = 100;
int reqWidth = 100;
int origHeight;
int origWidth;

imageLocation = Server.MapPath(Request.QueryString["Image"]);
if (Request.QueryString["Height"] != null){
reqHeight = Convert.ToInt32(Request.QueryString["Height"]);
}
if (Request.QueryString["ForceAspect"] != null){
forceaspect = Convert.ToBoolean(Request.QueryString["ForceAspect"]);
}
if(Request.QueryString["Width"] != null){
reqWidth = Convert.ToInt32(Request.QueryString["Width"]);
}
if (Request.QueryString["ForceAspect"] == "true"){
forceaspect = true;
}

System.Drawing.Bitmap origBitmap = new
System.Drawing.Bitmap(imageLocation);
origHeight = origBitmap.Height;
origWidth = origBitmap.Width;

if (forceaspect){
//Force Aspect Change
newHeight = reqHeight;
newWidth = reqWidth;
}
else if (origBitmap.Height >= origBitmap.Width){
//Portrait
newHeight = reqHeight;
newWidth = (int)(((double)origBitmap.Width / (double)origBitmap.Height) *
reqHeight);
}
else{
//Landscape
newWidth = reqWidth;
newHeight = (int)(((double)origBitmap.Height / (double)origBitmap.Width)
* reqWidth);
}

System.Drawing.Bitmap outputImage = new System.Drawing.Bitmap(origBitmap,
newWidth, newHeight);
outputImage.SetResolution(72, 72);

//outputImage.InterpolationMode = InterpolationMode.HighQualityBicubic;
// does not work
System.Drawing.Imaging.ImageFormat outputFormat =
(System.Drawing.Imaging.ImageFormat)imageOutputFormatsTable[origBitmap.RawFormat.Guid];

outputImage.Save(Response.OutputStream, outputFormat);
outputImage.Dispose();
origBitmap.Dispose();
}
catch (Exception ex){
//log error so we may know the problem. you need to have write permits, of
course on log path
System.IO.StreamWriter sw=null;
try{
sw=new System.IO.StreamWriter(Server.MapPath("error.txt"),true);
sw.WriteLine("Error : " + ex.Message + " processing " +
Request.QueryString["Image"]);
}
catch{}
finally{sw.Close();}
//now display the error image
Response.Redirect("thumberror.gif");
}
}
</script>


.



Relevant Pages

  • A Thumbnail Script
    ... I found a script that converts a regular size image to a thumbnail. ... int newHeight; ... newWidth = reqWidth; ...
    (microsoft.public.dotnet.general)
  • A Thumbnail Conversion Script
    ... I found a script that converts a regular size image to a thumbnail. ... int newHeight; ... newWidth = reqWidth; ...
    (microsoft.public.dotnet.languages.csharp)
  • Feedback on scripting design
    ... At the start of the game, a startup script is called, which is responsible for setting up all the initial game values, selecting the starting map, and any other miscellaneous things you want taken care of at the beginning of the game. ... Interface_NewMap(int Width, int Height); ... Interface_Hurt(int MonsterID, int Damage, int DamageTypeFlags); ...
    (rec.games.roguelike.development)
  • Re: Two Explorer thumbnail bugs
    ... I will play with your issue and the script. ... related to the EXIF data of these JPGs... ... EXIF has its own thumbnail field ... not update that filed and windows explorer is using it to update its own ...
    (microsoft.public.windowsxp.photos)
  • Re: Thumbnail Viewer adjusting
    ... as a thumbnail), resize it dynamically for thumbnail, so this did not ... //write out HTML for Image Thumbnail Viewer plus loading div ... Don't test host object properties by type conversion (they are known ... None of this is needed unless the script introduces memory leaks. ...
    (comp.lang.javascript)

Loading