22.08.2013 Views

ColdFusion Developer's Guide

ColdFusion Developer's Guide

ColdFusion Developer's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Beta Beta Beta Beta Beta Beta Beta<br />

Enforcing size restrictions<br />

<strong>ColdFusion</strong> provides several functions for retrieving information associated with images,<br />

including the height and width of an image. For example, you can use the ImageGetWidth<br />

and ImageGetHeight functions to determine whether an image is too large to upload to a<br />

website or database.<br />

The following example shows how to prevent users from uploading images that are greater<br />

than 300 pixels wide or 300 pixels high:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

The image you uploaded was too big. It must be less than 300 pixels<br />

wide and 300 pixels high. Your image was #imageGetWidth(myImage)# pixels<br />

wide and #imageGetHeight(myImage)# pixels high.<br />

<br />

<br />

For information about retrieving image metadata, see the ImageGetEXIFTag,<br />

ImageGetIPTCTag, and ImageInfo functions in the CFML Reference.<br />

Compressing JPEG images<br />

To reduce the size of large files, you can convert a JPEG file to a lower quality image by using<br />

the write action of the cfimage tag. Specify a value between 0 (low) and 1 (high) for the<br />

quality attribute, as the following example shows:<br />

<br />

You can perform the same operation by using the ImageWrite function:<br />

<br />

<br />

1094 Creating and Manipulating <strong>ColdFusion</strong> Images

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!