© Efflare Systems
website : e-mail

index | examples | api | language
Example 2 • Generating thumbnails
In this example we will generate thumbnails of watch.jpg and tc.jpg.
<cfx_imageflare source="
  b = Bitmap('#expandpath('.\watch.jpg')#')
  b.resize(200,0)
  b.save('#expandpath('.\example02a.jpg')#')
">

     In this example we create a Bitmap object with Bitmap('#expandpath('.\watch.jpg')#').
As the ImageFlare API denotes, this constructor loads the named image into the new Bitmap object immediately.

We then resize and save the image. You'll notice the second argument of the resize function is 0. As the API states, when either the width or height is zero, it will be calculated automatically keeping the image proportion the same.

Although resizing and converting images is most certainly possible with ImageFlare, our ImageCR custom tag specializes in these things.
ImageCR is somewhat easier to use and does not have the overhead of an embedded scripting engine. ImageCR is assembly optimized compiled code.
<cfx_imageflare source="
  b = Bitmap( '#expandpath('.\tc.jpg')#' )
  b.resize( 0, 150 )
  b.crop( (b.width/2)-75, 0, (b.width/2)+75, 150 )
  b.save( '#expandpath('.\example02b.jpg')#' )
">

     In this example we do something a little bit different. After resizing the image we crop it with :

b.crop( (b.width/2)-75, 0, (b.width/2)+75, 150 )

This basically cuts out the middle section of the image, so it is not too wide. If you look at the original tc.jpg you can see it is proportionately wide. The above script cuts an optimal square from the middle of the image for the resulting thumbnail.

The following progression demonstrates this process :

Original thumbnail...      Cropping...      Fin.

    
    

As usual, feel free to contact us with questions.
Click here to return to the examples index, or continue on to Example 3.