From psw@wherry.com Sat Jan 8 00:35:10 2005 Date: Sun, 07 Mar 2004 11:49:20 -0500 From: Phillip Wherry To: wsanford@wsanford.com Subject: resizer.php is a lot more powerful now [ The following text is in the "ISO-8859-1" character set. ] [ Your display is set for the "US-ASCII" character set. ] [ Some characters may be displayed incorrectly. ] I've spent a few minutes (OK, close to an hour) working on the resizer.php script. It's a lot more capable now that it was. Here's a summary for the three different ways the script can be invoked. It's explained in more detail following the summary. Brackets indicate things that are optional; you don't enter them. METHOD 1: scale factor (this is the only way previously supported) resizer.php?f[ilename]=f &s[cale]=n (where n is 1, 2, 4, or 8) [&q[uality]=n] (where n is a percentage 0-100; default is 90) METHOD 2: width x height resizer.php?f[ilename]=f &w[idth]=x (where x is an integer between 1 and 4096) &h[eight]=y (where y is an integer between 1 and 4096) [&o[ption]=z] (where z is the letter "u" (unlock proportions), "g" (grow to fit), or "s" (shrink to fit). The default is "none of the above".) [&q[uality]=n] (where n is a percentage 0-100; default is 90) METHOD 3: percentage resizer.php?f[ilename]=f &p[ercent]=n (where n is an integer between 1 and 400) [&q[uality]=n] (where n is a percentage 0-100; default is 90) Some notes on its use: The old form of the URL still works fine: resizer.php?filename=x&scale=y&quality=z ...where scale is 1, 2, 4, or 8 (which results in a 1/x-scale image). What's new: It's now possible to abbreviate things to their first letter. So, for example, this would work: resizer.php?f=image.jpg&s=2&q=80 There are also a couple of new invocation formats: resizer.php?filename=f&width=x&height=y&option=z&quality=q ...will scale the image to x-by-y dimensions. For example: resizer.php?f=image.jpg&w=320&h=240 ...would fit the image into a 320x240-pixel box. By default, the image's proportions are preserved. If, for example, you started with a 640x480 image and then used: resizer.php?f=image.jpg&w=320&h=320 ...you would NOT get a distorted image. Instead, the resizer would make the image as large as possible within the 320x320 box (which would be 320x240 in this case). Note, however, that you can't use WIDTH= and HEIGHT= tags in an IMG tag and still expect this to work. If you did something like this: ...the resizer would deliver a 320x240 image (preserving proportions), which the browser would then distort to 320x320. If you really intend to distort an image to fit into a particular space, it is possible to unlock the image proportions: resizer.php?f=image.jpg&w=320&h=320&option=u (or just o=u) In addition, there are two other options: "g" (for "grow") and "s" (for "shrink"). These are useful when you don't know the size of an image in advance, but want it to be no bigger (or smaller) than a particular box. For example: resizer.php?f=image.jpg&w=320&h=240&o=s ...would ensure that the file image.jpg consumes no more than 320x240 pixels (this is particularly useful when working within table cells). If the image is already smaller than this, it's not touched. If it's larger, it's shrunk so that the image fits within the specified box. Similarly: resizer.php?f=image.jpg&w=320&h=240&o=g ...will grow the image so that it will reach the edges of a 320x240 pixel box. If it's already bigger, it's not touched. Finally, it's possible to specify a percentage scale now: resizer.php?f=image.jpg&p=75 ...would result in a 3/4-scale image. Enjoy! Phil