Examples

On this page you will find CFML examples of ImageCR 3 in use.

The code listings are automatically formatted to fit the screen. Additionally, CFX_ImageCR attributes in the code are hyperlinked to their definitions. However, the usual link underlines were removed to improve readability.

Click the to view code in original formatting and without colors or links.

Click the to view the results of the executed code on its own page.

Basic

<cfx_imagecr3 load="#expandpath('example.jpg')#" 
              save="#expandpath('example-resaved.jpg')#" >
basic.cfm Plain Code...View Result...
This example loads example.jpg and saves it as example-resaved.jpg. In the process, ImageCR just happens to have optimized this image, reducing the size by over 20k, without a noticable difference in the image quality.

The result of this example is a blank page. The tag just performs the operation, it does not output any text or html.

Resizing

<cfx_imagecr3 load="#expandpath('example.jpg')#" 
              save="#expandpath('example-resized.jpg')#"
              resize="200x200" > <cfoutput> <img src="example-resized.jpg"> </cfoutput>
resize.cfm Plain Code...View Result...

This example...

• loads example.jpg
• resizes the image to 200x200
• saves as example-resized.jpg

Shown to the right is the result, example-resized.jpg.

Cropping

<cfx_imagecr3 load="#expandpath('example.jpg')#" 
              save="#expandpath('example-cropped.jpg')#"
              crop="200x200"
              anchor="center" > <cfoutput> <img src="example-cropped.jpg"> </cfoutput>
crop.cfm Plain Code...View Result...

This example...

• loads example.jpg
• crops a 200x200 pixel area from the center of the image
• saves as example-cropped.jpg

Shown to the right is the result, example-cropped.jpg.

Simple Gallery

<cfset dir="#ExpandPath('photos/')#">

<cfdirectory name="dirlist" directory="#dir#" filter="*.jpg">

<cfoutput query="dirlist">  
  
  <cfx_imagecr3 load="#dir##dirlist.name#" 
              save="#expandpath('thumbnails/')#"
              resize="x100" > <a href="photos/#dirlist.name#"> <img src="thumbnails/#imagecr.filename#" border="0"></a> </cfoutput>
gallery.cfm Plain Code...View Result...
This example obtains a listing of all jpg files in the "photos" subdirectory. Then, it loops over that list creating thumbnails for each image, saving the thumbnails to the "thumbnails" subdirectory with autonames.

Each thumbnail is 100 pixels high, and the width is calculated proportionately. ( see: resize, RectString )

Each thumbnail is displayed and links to the full size image, creating a simple gallery.

View Result...See the results »

Be sure to look at a couple of the thumbnails' filenames. They are autonamed since save is a directory.

Square Gallery

<cfset dir="#ExpandPath('photos/')#">

<cfdirectory name="dirlist" directory="#dir#" filter="*.jpg">

<cfoutput query="dirlist">  
  
  <cfx_imagecr3 load="#dir##dirlist.name#" 
              save="#expandpath('thumbnails/')#"
              resize="]100"
              recrop="100"
              anchor="center" > <a href="photos/#dirlist.name#"> <img src="thumbnails/#imagecr.filename#" border="0"></a> </cfoutput>
gallery2.cfm Plain Code...View Result...
This is similar to the Simple Gallery, but makes use of boxing modifiers and recrop to create thumbnails of like size regardless of the original image sizes. Resulting thumbnails are 100x100 pixels and edges are cropped as necessary.

View Result...See the results »

CSS Gallery

<style>
  .centeredthumb {
    width: 100px;
    height: 100px;
    background: #f0f0f0 no-repeat center;
    border: 1px solid #c0c0c0;
  }
</style>

<cfset dir="#ExpandPath('photos/')#">

<cfdirectory name="dirlist" directory="#dir#" filter="*.jpg">

<cfoutput query="dirlist">  
    
  <cfx_imagecr3 load="#dir##dirlist.name#" 
              save="#expandpath('thumbnails/')#"
              resize="[100"
              recrop="100" > <!--- the next line helps keep lines short for the documentation ---> <cfset css="background-image:url('thumbnails/#imagecr.filename#');"> <a href="photos/#dirlist.name#"> <img class="centeredthumb" style="#css#" src="blank.gif" border="0"></a> </cfoutput>
gallery3.cfm Plain Code...View Result...
This is similar to the Square Gallery, but creates thumbnails without cropping, and centers them in 100x100 blocks with CSS. Note the use of the box-in modifier, "[". This creates images which fit inside a 100 pixel square.

View Result...See the results »

GetImageInfo

<cfx_imagecr3 getimageinfo="#expandpath('example.jpg')#" >
<cfoutput>
  <pre>
    Width    = #imagecr.width#
    Height   = #imagecr.height#    
    DPI      = #imagecr.dpi# 
    FileSize = #imagecr.filesize#
  </pre>
</cfoutput>
getimageinfo.cfm Plain Code...View Result...
This example shows how easy getimageinfo mode is. Image details are retrieved from example.jpg and displayed.

Website Screenshot

<cfset bmpfile="#expandpath('efflare.bmp')#">
<cfset giffile="#expandpath('efflare.gif')#">

<cfset gotscreen="#fileexists(bmpfile)#">
<cfif not gotscreen>
  <cfx_url2bmp url="http://efflare.com" bmp="#bmpfile#">
</cfif>

<cfx_imagecr3 load="#bmpfile#" 
              save="#giffile#"
              crop="700x700+0+8"
              anchor="north" > <img border="1" src="efflare.gif">
url2bmp.cfm Plain Code...View Result...
This example shows one of our free tags, cfx_url2bmp, in use alongside cfx_ImageCR to obtain an efficient gif screenshot of http://efflare.com. ImageCR loads the created bmp, crops a 700 pixel wide section from the top center, and saves efficiently as a well suited gif. ( see also : Popular Image Formats)

Take a look at the resulting 25k gif here » View Result...

cfx_url2bmp is a free, but unsupported, tag one of our developers wrote as a proof of concept one slow weekend. You can download it from our website at http://efflare.com/download/.

This technique allows for some interesting implementations. For example, when used with something like the Simple Gallery above you could create contact sheets for groups of images. The possibilities are surprising.



« How does it work? (prev) (next) Advanced »

Copyright © Efflare Systems