Images

Overview

In the course of a scrape it you might want to gather images associated with the other information being gathered. These methods are provided to not only download the images but to gather size information and resize to your desired size.

These methods are only available to enterprise edition users.

getImageHeight

int sutil.getImageHeight ( String imagePath ) (enterprise edition only)

Description

Get the height of an image.

Parameters

  • imagePath File path to the image, as a string.

Return Values

Returns the height in pixels of the image file, as an integer. If the file doesn't exist or is not an image an error will be thrown and -1 will be returned.

Change Log

Version Description
5.0 Moved from session to sutil.
4.5 Available for enterprise edition.

Examples

Write Image Height to Log

 // Output the height of the image to the log.
 session.log( "Image height: " + sutil.getImageHeight( "C:/my_image.jpg" ) );

getImageWidth

int sutil.getImageWidth ( String imagePath ) (enterprise edition only)

Description

Get the width of an image.

Parameters

  • imagePath File path to the image, as a string.

Return Values

Returns the width in pixels of the image file, as an integer. If the file doesn't exist or is not an image an error will be thrown and -1 will be returned.

Change Log

Version Description
5.0 Moved from session to sutil.
4.5 Available for enterprise edition.

Examples

Write Image Width to Log

 // Output the width of the image to the log.
 session.log( "Image height: " + sutil.getImageWidth( "C:/my_image.jpg" ) );

resizeImage

Overview

Internally, only one function is used to resize all images; however, to facilitate the resizing of images, we have provided you with three methods. Each method will help you specify what measurement is most important (width or height) and whether the image should retain its aspect ratio.

  1. resizeImageFixHeight() [sutil] - Resize image, retaining aspect ratio, based on specified height.
  2. resizeImageFixWidth() [sutil] - Resize image, retaining aspect ratio, based on specified width.
  3. resizeImageFixWidthAndHeight() [sutil] - Resize image to a specified size (will not check aspect ratio).

resizeImageFixHeight

void sutil.resizeImageFixHeight ( String originalFile, String newFile, int newHeightSize, boolean deleteOriginalFile ) (enterprise edition only)

Description

Resize image, retaining aspect ratio, based on specified height.

Parameters

  • originalFile File path of the image to be resized, as a string.
  • newFile File path when the new image should be created, as a string.
  • newHeightSize The height of the resized image in pixels, as a integer.
  • deleteOriginalFile Whether the origionalFile should be retained, as a boolean.

Return Values

Returns void. If an error is encountered it will be thrown.

Change Log

Version Description
5.0 Moved from session to sutil.
4.5 Available for enterprise edition.

Examples

Resize Image to Specified Height

 // Resizes a JPG to 100 pixels high, maintaining the
 // aspect ratio. After the image is resized, the original
 // will be deleted.

 sutil.resizeImageFixHeight( "C:/my_image.jpg", "C:/my_image_thumbnail.jpg", 100, true );

resizeImageFixWidth

void sutil.resizeImageFixWidth ( String originalFile, String newFile, int newWidthSize, boolean deleteOriginalFile ) (enterprise edition only)

Description

Resize image, retaining aspect ratio, based on specified width.

Parameters

  • originalFile File path of the image to be resized, as a string.
  • newFile File path when the new image should be created, as a string.
  • newWidthSize The width of the resized image in pixels, as a integer.
  • deleteOriginalFile Whether the origionalFile should be retained, as a boolean.

Return Values

Returns void. If an error is encountered it will be thrown.

Change Log

Version Description
5.0 Moved from session to sutil.
4.5 Available for enterprise edition.

Examples

Resize Image to Specified Width

 // Resizes a JPG to 100 pixels wide, maintaining the
 // aspect ratio. After the image is resized, the original
 // will be deleted.

 sutil.resizeImageFixWidth( "C:/my_image.jpg", "C:/my_image_thumbnail.jpg", 100, true );

resizeImageFixWidthAndHeight

void sutil.resizeImageFixWidth ( String originalFile, String newFile, int newWidthSize, int newHeightSize, boolean deleteOriginalFile ) (enterprise edition only)

Description

Resize image to a specified size.

Parameters

  • originalFile File path of the image to be resized, as a string.
  • newFile File path when the new image should be created, as a string.
  • newWidthSize The width of the resized image in pixels, as a integer.
  • newHeightSize The height of the resized image in pixels, as a integer.
  • deleteOriginalFile Whether the origionalFile should be retained, as a boolean.

Return Values

Returns void. If an error is encountered it will be thrown.

Change Log

Version Description
5.0 Moved from session to sutil.
4.5 Available for enterprise edition.

This method can cause distortions of the image if the aspect ratio of the original and target images are different.

Examples

Resize Image to Specified Size

 // Resizes a JPG to 100x100 pixels.
 // After the image is resized, the original
 // will be deleted.

 sutil.resizeImageFixWidthAndHeight( "C:/my_image.jpg", "C:/my_image_thumbnail.jpg", 100, 100, true );