UMD Web Site

Page Content   Main Links   Page Links   Utility Links   Search   Footer Links

ColdFusion Development Project

cf_imageprocessing

Description: Resizes and reduces the file size of an image to make it suitable for Web sites. The following actions are taken depending on the image type:
  • JPG/JPEG: resize and reduce the quality to 50 percent.
  • GIF: convert to JPG, then resize and reduce the quality.
  • PNG: same as JPG.
  • All other formats are ignored at this time.
Syntax:
<cf_imageprocessing
  imagefilename = "file_name"
  maxheight = "pixels"
  maxwidth = "pixels"
  padding = "Yes" or "No"
  padcolor = "hex_colorcode" or "color_name"
  align = "left" or "right" or "center"
  valign = "top" or "bottom" or "center">
See also: cf_imageinfo
Attributes:
Attribute Name Required/Optional Default Description
imagefilename required
Absolute, physical path to the image file. The image file must be physically located on the same server.
maxheight at least one of maxheight or maxwidth required
Maximum allowable height of the image. To preserve the aspect ratio of the height and width of the image, the resulting height may be smaller than the specified value.
maxwidth at least one of maxheight or maxwidth required
Maximum allowable width of the image. To preserve the aspect ratio of the height and width of the image, the resulting width may be smaller than the specified value.
padding optional No Padding around the image. If the resized image is smaller than the width and height specified in maxwidth and maxheight the remaining pixel area can be padded with padcolor as part of the image file.
padcolor optional #FFFFFF Color of the padding pixels, if padding="Yes" and the image does not fill the entire area defined by maxwidth and maxheight.
align optional left Horizontal alignment of the reformatted image in the area defined by maxwidth and maxheight. Only used when padding="Yes".
valign optional top Vertical alignment of the reformatted image in the area defined by maxwidth and maxheight. Only used when padding="Yes".
Returns: A variable imgProcResult is created as local variable in the calling page. The values are:

imgProcResult = file not found if the specified image file does not exist
imgProcResult = invalid file format if the image file format is not supported
imgProcResult = missing parameter if neither maxwidth nor maxheight are specified
imgProcResult = ok (<image filename>) if everything seems to be ok. The absolute physical path and filename of the reformatted image is returned.

Example: A border="2" is added in the IMG tags to visualize the padding. The border is not part of the image file. There are no height and width attributes set in the IMG tags.

Original image:

Reformatting with only a height constraint:
The height is forced to 100 pixels. The width of the image is adjusted automatically to maintain the aspect ratio of the original image.
<cf_imageprocessing imagefilename="#expandPath('cograilway.jpg')#" maxheight="100">


Reformatting with a height and a width constraint:
The height and width are not to exceed 100 pixels. Since the width of the original image is larger than the height, the resized image is 100 pixels wide, but its height is less than 100 pixels to maintain the original aspect ratio.
<cf_imageprocessing imagefilename="#expandPath('cograilway.jpg')#" maxheight="100" maxwidth="100">


Reformatting with a height and a width constraint and additional padding:
The height and width are not to exceed 100 pixels. Again, the width of the original image is larger than the height. Therefore the resized image is 100 pixels wide and no horizontal padding is added. The reduced height is less than 100 pixels to maintain the original aspect ratio, and with a vertically centered alignment valign="center" padding is added at the top and the bottom of the image.
<cf_imageprocessing imagefilename="#expandPath('cograilway.jpg')#"
                    maxheight="100" maxwidth="100"
                    padding="Yes" padcolor="#0000FF"
                    align="center" valign="center">


Notes: The image transformation is done as a subprocess in the background. The reformatted image is replacing the original image without changing its filename. For large image files, the reformatting of the image may take several seconds - longer than the average response of the Web server to the browser takes. Therefore you may not see the results immediately and need to account for it in your Web application.

In order to match our file naming conventions the following actions are taken on the file names:
  • The image filename is converted to all lower case letters. Special characters and white space are removed from the file name.
  • Image filenames without a file extension are appended with proper extension based on the image type.
Go here for information on the underlying image manipulation software.

Contact Info:

Email: webdevelopment@umassd.edu - Web Design & Development

Main Links

Page Links

Utility Links

Search

 
Text Only Options

Top of page


Text Only Options

Open the original version of this page.

Usablenet Assistive is a UsableNet product. Usablenet Assistive Main Page.