473,395 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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)imageOutputFor matsTable[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>
Sep 27 '06 #1
0 1272

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Max Quordlepleen | last post by:
Apologies for the crossposting, I wasn't sure which of these groups to ask this in. I have been lurking in these groups for a week or so, trying to glean what I need to design a simple, clean...
2
by: asad | last post by:
Hello friends, how ru all, i have some problem about saving created thumbnail, following is the code i use for creating thumbnail but thumbnail was not saved it is on memory which method is used to...
4
by: Øyvind Isaksen | last post by:
Hello! Does anyone know about an ASP.NET thumbnail script that generate thumbnail with MAX quality? Have tested some scripts, but the thumbnail is not getting as good quality as I need. This...
8
by: barb | last post by:
So that the world at large benefits from our efforts, here is one fully documented way to use Windows Irfanview freeware to create thumbnail web galleries (http://www.irfanview.com). STEP 1:...
0
by: David R. | last post by:
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...
1
by: David R. | last post by:
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...
3
by: lolo | last post by:
hello. happy new year. I'm trying to build a website for my wife and she is adament on having a horizontal thumbnail scrolling div. great. I have a good vertical scrolling thing, but can't...
1
by: veer165 | last post by:
I have a list of items... And i want a little thumbnail of each item to be displayed when the mouse is over a particular text ... Say if i have a list of fruits i want an apple thumbnail on the...
7
by: mishrarajesh44 | last post by:
hii all Truly telling i hav got this code from net & i am finding error while running the code below.. code:- <?php $idir = "photo/"; // Path To Images Directory $tdir =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.