<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>effengud software &#187; resize</title>
	<atom:link href="http://www.effengud.com/index.php/tag/resize/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.effengud.com</link>
	<description>It&#039;s Simple. It&#039;s Elegant. It&#039;s effengud!™</description>
	<lastBuildDate>Tue, 10 Aug 2010 16:14:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Proportional Image Resizing(within a constrained area)</title>
		<link>http://www.effengud.com/index.php/2009/08/01/proportional-image-resizing/</link>
		<comments>http://www.effengud.com/index.php/2009/08/01/proportional-image-resizing/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 14:59:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://www.effengud.com/wp/?p=12</guid>
		<description><![CDATA[History
The IMGSZ code presented in my earlier article, Determining Image Properties in ASP, was written in response to my need to be able to fit images proportionally within a given area. My client had asked me to develop a photo gallery application for their site, and the photo gallery was to display photos surrounded by [...]]]></description>
			<content:encoded><![CDATA[<h2>History</h2>
<p>The IMGSZ code presented in my earlier article, <a href="http://www.effengud.com/index.php/2009/08/01/determining-image-properties-using-asp/">Determining Image Properties in ASP</a>, was written in response to my need to be able to fit images proportionally within a given area. My client had asked me to develop a photo gallery application for their site, and the photo gallery was to display photos surrounded by a complex graphical &#8216;photo album&#8217; motif. As a result, all photos (regardless of their original size) needed to &#8216;fit&#8217; within a defined pixelspace.</p>
<p>Many questions ensued: So how would I accomplish that within HTML? Would I need to buy a component? And is  <em>&#8216;pixelspace&#8217;</em> even a real word?  Although I mentioned the possibility of enhancing the IMGSZ routines to allow for proportional resize, I left it up to the readers of that original article to enhance those routines to do the proportional sizing. However, <em>so many</em> of you have asked for the resizing routine that I am pleased (relieved?) to offer it here now.</p>
<h2>Why Do I Need It?</h2>
<p>If you are just learning HTML (or any of its younger variants) you already know that the <code>IMG</code> tag has <code>HEIGHT</code> and <code>WIDTH</code> properties that can be used to force an image to a particular size. However, it has no easy way to do a proportional resize that fits in a desired area. For example, let&#8217;s say you&#8217;re showing images in a table for an on-line product catalog. To make things look nice, you&#8217;re defining the size of the image presented to 100&#215;75 pixels. So you may decide to use <code>WIDTH="100" HEIGHT="75"</code> in your <code>IMG </code>tag for each picture. What will happen is that images may get squashed or stretched in ways that you (and your customers) do not find pleasing. This IMGSZ add-on function will allow you to overcome that problem.</p>
<h2>How Does It Work?</h2>
<p>The <code>ImageResize</code> function is passed an image filename, a maximum width and a maximum height. The function returns either a <code>HEIGHT=xxx</code> or a <code>WIDTH=xxx</code> string that you embed in your IMG tag to provide the proportional resize.</p>
<h2>So How Do I Use It?</h2>
<p>Using the function can be as simple as embedding a function call in your <code>IMG</code> tag. For example, the following code will present an image proportionally in a 100&#215;75 pixel area:</p>
<table border="0" width="95%">
<tbody>
<tr>
<td width="100%" bgcolor="#cccccc"><code><br />
response.write "&lt;img src=""graphic.gif"" " &amp; ImageResize(strImageName, 100, 75) &amp; "&gt;"<br />
</code></td>
</tr>
</tbody>
</table>
<p>The parameters passed to the function are as follows:</p>
<table border="1" cellspacing="1" width="75%" align="center">
<tbody>
<tr>
<th colspan="2"><code>ImageResize</code> Parameters</th>
</tr>
<tr>
<th>Property</th>
<th>Description</th>
</tr>
<tr>
<td><code>strImageName</code></td>
<td>The actual filename (on the server&#8217;s drives)<br />
of the image you will display</td>
</tr>
<tr>
<td><code>intDesiredWidth</code></td>
<td>The width constraint</td>
</tr>
<tr>
<td><code>intDesiredHeight</code></td>
<td>The height constraint</td>
</tr>
</tbody>
</table>
<p>As a further example, let&#8217;s look at some simple test code. This code will look at your server&#8217;s <code>C:\</code> drive, root directory, and display all GIF images that it finds there in a table. The images will be proportionally resized to fit within a 75&#215;45 pixel area. Be sure to <a href="/demos/PropResizeTest.asp">view the live demo</a>!</p>
<table border="0" width="95%">
<tbody>
<tr>
<td width="100%" bgcolor="#cccccc"><code> </code></p>
<pre>&lt;%
   ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   ':::                                                   :::
   ':::  SCRIPT:   testpropresize.asp                     :::
   ':::  AUTHOR:   Mike Shaffer                           :::
   ':::  DATE:     11-Jan-01                              :::
   ':::  PURPOSE:  Test/show the operation of the resize  :::
   ':::            (proportional) function                :::
   ':::                                                   :::
   ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::
%&gt;
  &lt;!--#INCLUDE FILE='imgsz.asp'--&gt;
  &lt;!--#INCLUDE FILE='propresize.asp'--&gt;
&lt;%
' To test, we'll just try to show all files with a .GIF
' extension in the root of C: by fitting them to a common
' area (75 pixels x 45 pixels)

dim objFSO, objF, objFC
dim f1, w, h, c, strType

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objF = objFSO.GetFolder("c:\")
Set objFC = objF.Files

response.write "&lt;table border=""1"" cellpadding=""5""&gt;"

For Each f1 in objFC
  if instr(ucase(f1.Name), ".GIF") then
     response.write "&lt;tr&gt;&lt;td&gt;" &amp; f1.name &amp; "&lt;/td&gt;&lt;td&gt;" &amp; _
         f1.DateCreated &amp; "&lt;/td&gt;&lt;td&gt;" &amp; f1.Size &amp; "&lt;/td&gt;&lt;td&gt;"

     if gfxSpex(f1.Path, w, h, c, strType) = true then
        response.write w &amp; " x " &amp; h &amp; " " &amp; c &amp; " colors&lt;/td&gt;"
        response.write "&lt;td&gt;&lt;img src=""" &amp; f1.Path &amp; """ " &amp; _
              ImageResize(f1.Path, 75, 45) &amp; " border=""1""&gt;&lt;/td&gt;"
     else
        response.write " &lt;/td&gt;&lt;td align=""center""&gt;bad image&lt;/td&gt;"
     end if

     response.write "&lt;/tr&gt;"

  end if
Next

response.write "&lt;/table&gt;"

set objFC = nothing
set objF = nothing
set objFSO = nothing
%&gt;</pre>
</td>
</tr>
</tbody>
</table>
<p>[<a href="/demos/PropResizeTest.asp">View the live demo!</a>]</p>
<h2>Enough Yakking Already, Show Me The Code!</h2>
<p>The code for the function (below) is quite simple, really. Here is a description of the steps it follows to do its magic:</p>
<ul>
<li>First, call the <code>gfxSpex</code> function (contained in <code>IMGSZ.ASP</code>) to determine<br />
the height and width (and color depth and validity!) of the image.</li>
<li>Determine the target image ratio and the file&#8217;s image ratio<br />
(width divided by depth)</li>
<li>If the file&#8217;s image ratio is greater-than the target image ratio,<br />
then we know that we have to size proportionally based on <code>WIDTH</code>,<br />
otherwise we size proportionally based on <code>HEIGHT</code> (and if it was<br />
not a valid image, return an empty resize string)</li>
</ul>
<p>Oops! I&#8217;m <em>yakking</em> again, here&#8217;s the code, already!</p>
<table border="0" width="95%">
<tbody>
<tr>
<td width="100%" bgcolor="#cccccc"><code> </code></p>
<pre>function ImageResize(strImageName, intDesiredWidth, intDesiredHeight)
   dim TargetRatio
   dim CurrentRatio
   dim strResize
   dim w, h, c, strType

   if gfxSpex(strImageName, w, h, c, strType) = true then
      TargetRatio = intDesiredWidth / intDesiredHeight
      CurrentRatio = w / h
      if CurrentRatio &gt; TargetRatio then  ' We'll scale height
         strResize = "width=""" &amp; intDesiredWidth &amp; """"
      else
         ' We'll scale width
         strResize = "height=""" &amp; intDesiredHeight &amp; """"
      end if
   else
      strResize = ""
   end if

   ImageResize = strResize
end Function</pre>
</td>
</tr>
</tbody>
</table>
<h2>Caveats</h2>
<p>You can integrate the <code>PROPRESIZE.ASP</code> contents into the <code>IMGSZ.ASP</code> code if you like. Note that this does NOT perform an actual resize of the graphical image file, only the visual representation of the image. What this means is that if you have an image that is 800&#215;600x24 bits which is 1 megabyte in size, and you ask the routine to scale the image to a 100&#215;75 pixel area, you will STILL be downloading that entire 1 megabyte of picture information from the server. If you want to do TRUE thumbnail file creation (on disk) you will need to obtain any one of the graphical components available today that offer this feature.</p>
<p><b>Article collateral materials:</b></p>
<p><img src="/elements/effendot.gif" alt="" width="7" height="7" /> <a href="/articles/propresize.html">Download the PROPRESIZE.ASP source code in text format</a><br />
<img src="/elements/effendot.gif" alt="" width="7" height="7" /> <a href="/articles/imgsz.html">Download the IMGSZ.ASP source code in text format</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.effengud.com/index.php/2009/08/01/proportional-image-resizing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
