ResizeImage function

Syntax

ResizeImage(URL.source_URL, URL.dest_URL, array_of_sizes [, type][, aspect_ratio])

Description

Use the ResizeImage function to create one or more resized copies of the source image. Depending on the image source, ResizeImage supports the following image formats only:

  • Record field: BMP and JPEG.

  • File system folder: BMP, GIF, JPEG, and PNG.

The resized images can be created in file system folder or in a database table. When the destination location is a file system folder, then the name of the resized image is created from the source image file name along with the resize dimensions. For example, if file1.jpg is resized to 40 x 60 pixels, then the resulting file name would be file14060.jpg. If the same file is resized to 10%, the resulting file name would be file110.jpg.

When a database table is specified as the destination location, the PS_PT_IMG_TMPSTORE table is used to temporarily store the images instead of the specified database table. Using the return code of the function invocation as a key value, your application must retrieve the resized images from the PS_PT_IMG_TMPSTORE table.

Column Name Data Type Description

PT_IMG_UUID*

Nbr

The return value of the ResizeImage method. All the resized images stored in database for a specific invocation are stored with this identifier.

PT_IMG_FILESEQNO*

Nbr

The sequence number for multiple resizings of the same source image file.

PT_IMG_WIDTH*

Nbr

The image width in pixels.

PT_IMG_HEIGHT*

Nbr

The image height in pixels.

PT_IMG_IMGNAME

Char

The file name of the source image.

PT_IMG_IMGDATA

Long

The image data for the re-sized image.

PSIMAGEVER

Nbr

The image version.

LAST_UPDATE_DTTM

DtTm

The last update timestamp.

OPRID

Char

The operator ID

* Represents a key field. The composite key for a specific resized image would consist of: PT_IMG_UUID + PT_IMG_FILESEQNO + PT_IMG_WIDTH + PT_IMG_HEIGHT + PT_IMG_IMGNAME.

Three image manipulation testing pages provide a sample application that allows an administrator to predefine resize dimensions (Image Size page), predefine groupings of dimensions (Image Group page), and then test the usage of these predefined groups for resizing images (Test Utility page). See System and Server Administration: Using Image Manipulation Utilities for more information.

Parameters

Parameter Description

URL. source_URL

Specifies the location of the source image (or images) as a URL object. The source location can be either a database record or a folder on the application server’s file system containing one or more image files.

When the URL object specifies a database record, you must define three URL properties: to specify the column name from which image data has to be read (), the column name from which the image name has to be taken (), and destination image type ().

  • IMG_DATA_COLUMN: The record field containing the image.

  • IMG_NAME_COLUMN: The record field containing the name of the image.

  • IMG_FILE_FORMAT: The record field specifying the image format. This field serves as a filter, and only images of the specified format are resized.

    Note: If the source record includes more than one row of data, then the IMG_FILE_FORMAT field is ignored.

URL. dest_URL

Specifies the location of the resized image (or images) as a URL object. The destination location can be either a database record or a folder on the application server’s file system.

Important: When the destination location is specified as a database record, the PS_PT_IMG_TMPSTORE table is used to temporarily store the images instead of the specified record. Using the return code of the function invocation as a key value, your application must retrieve the resized images from the PS_PT_IMG_TMPSTORE table. See the “Description” for more information on using the PS_PT_IMG_TMPSTORE table.

array_of_sizes

Specifies resize dimensions as an array of integer. The contents of the array are retrieved in pairs or one-by-one depending on the value of the type parameter. In addition, the array must be terminated with two 0s or one 0, depending on the type parameter.

  • If type is 0 (%Resize_ByDimensions), the values in the array are retrieved in pairs representing the width and height (in pixels) of the resize dimensions. Terminate the array with two 0s. For example, the following array would resize the images to 20x20 pixels, 80x100 pixels, and to a width of 40 pixels maintaining the source images’ aspect ratio:

    &resize_array = CreateArray(20, 20, 80, 100, 40, 0, 0, 0);
  • If type is 1 (%Resize_ByPercentage), the values in the array are retrieved one-by-one representing the percentage to resize the images. Terminate the array with a single 0. For example, the following array would resize the images to 10% and 50%:

    &resize_array = CreateArray(10, 50, 0);

Important: Oracle recommends that you do not resize images to dimensions larger than the original size or to a percentage larger than 100%.

type

Specifies an optional numeric value indicating how to retrieve the values from the array_of_sizes array:

  • %Resize_ByDimensions (0) – The values in the array are retrieved in pairs representing the width and height (in pixels) of the resize dimensions.

  • %Resize_ByPercentage (1) – The values in the array are retrieved one-by-one representing the percentage to resize the images.

aspect_ratio

Specifies an optional Boolean value indicating whether to maintain the aspect ratio of the source image:

  • If aspect_ratio is True and either the height or width is 0, the aspect ratio of the source image is maintained. Otherwise, if both height and width are non-zero values, then aspect_ratio is ignored and the image is resized to the specified aspect ratio.

  • If aspect_ratio is False, then a resize is performed only if both height and width are non-zero values. Otherwise, if either the height or width is 0, no resize is performed.

True is the default value. In addition, the aspect_ratio parameter is ignored when the type parameter is 1 (%Resize_ByPercentage).

Returns

An Integer value representing the unique identifier for the resize invocation. A negative number indicates that the function terminated with an error.

Example

In the following example, a Resize method is defined to invoke the ResizeImage function. The source and destination URLs are passed into the method and then on to the function invocation. The third input parameter to the method is a group of predefined sizes. These predefined sizes are retrieved from a table and are converted into the &ImgDimensions array, which is the third required input parameter to the ResizeImage function.

method Resize
   /+ &SourceImgPath as String, +/
   /+ &DestImagPath as String, +/
   /+ &ImgGroupDefn as String +/
   /+ Returns Number +/
   Local number &retcode;
   Local Rowset &RS1, &RS2;
   Local Record &REC_IMGGROUP, &REC_SIZEDEFN;
   Local string &ImgSizeName;
   Local number &I, &width, &height;
   Local array of number &ImgDimensions;
   &ImgDimensions = CreateArray(0);
   &RS1 = CreateRowset(Record.PT_IMG_IMGGROUP);
   &RS1.Fill("where PT_IMG_GROUPNAME = :1", &ImgGroupDefn);
   Local Row &dimrow;
   For &I = 1 To &RS1.ActiveRowCount
      &dimrow = &RS1.GetRow(&I);
      &ImgSizeName = &dimrow.PT_IMG_IMGGROUP.PT_IMG_SIZENAME.Value;
      SQLExec("SELECT PT_IMG_WIDTH, PT_IMG_HEIGHT FROM PS_PT_IMG_SIZEDEFN WHERE PT_IMG_SIZENAME = :1", &ImgSizeName, &width, &height);
      &ImgDimensions.Push(&width);
      &ImgDimensions.Push(&height);
   End-For;
   If Exact(Left(&SourceImgPath, 4), "URL.") Then
      If Exact(Left(&DestImagPath, 4), "URL.") Then
         &retcode = ResizeImage(@(&SourceImgPath), @(&DestImagPath), &ImgDimensions);
      Else
         &retcode = ResizeImage(@(&SourceImgPath), &DestImagPath, &ImgDimensions);
      End-If
   Else
      If Exact(Left(&DestImagPath, 4), "URL.") Then
         &retcode = ResizeImage(&SourceImgPath, @(&DestImagPath), &ImgDimensions);
      Else
         &retcode = ResizeImage(&SourceImgPath, &DestImagPath, &ImgDimensions);
      End-If
   End-If;
   Return &retcode;
end-method;