473,395 Members | 1,975 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 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 28 '06 #1
1 1574
David,

You know that there is a getthumbnail method which does this mostly in three
rows.
http://msdn.microsoft.com/library/de...imagetopic.asp

I hope I don't disaprove you to much?

Cor
"David R." <da***********@nospam.comschreef in bericht
news:eh**************@TK2MSFTNGP06.phx.gbl...
>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 28 '06 #2

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...
8
by: Chris Dewin | last post by:
Hi. I run a website for my band, and the other guys want an image gallery. I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client...
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...
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...
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...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.