Image Process

Image processing component. The component reads images of any type that .Net understands (jpeg, gif, png, bmp, tif, and possibly others). It can execute simple commands, like resizing, and convert images to a different type.

File modes: Batch

File mode: Batch

A variable number of files are generated and saved in the database.

SQL

SQL Call: Commands (mandatory)

Statement to extract images and commands.

May modify database: No

Parameters

@Command bit
Set to 1 when component wants commands.

Resultset: Images and commands (optional)

Resultset with commands. Do not send too many large images -- the whole resultset is held in memory.
Table count: repeated zero or more times
Row count: zero or more rows
Columns
<xxx> mandatory binary
Image to process
<xxx>filename mandatory string
Name of image
Command optional string
Command to run on image. To run several commands they must be delimited by semicolon.
Possible value Description
crop(<x>,<y>,<width>,<height>) Crop image to the requested width and height, starting from pixel x, y.
getMetadata Extracts metadata from the image and then performs the Store metadata call.
maxsize(<width>,<height>) Fit image to requested size, preserving aspect ratio. For example, both maxsize(100,100) and size(100,100) would convert a 500x400 image to a 100x80 image. Unlike the size command, the maxsize command will only shrink images, never grow them. A 50x40 image would stay as a 50x40 image.
size(<width>,<height>) Fit image to requested size, preserving aspect ratio. For example, size(100,100) would convert a 500x400 image to a 100x80 image. The command can also scale images up, for example size(100,100) would grow a 50x40 image to a 100x80 image.
thumb(<width>,<height>) Force image to requested size, preserving aspect ratio, and padding with transparent (for png) or white pixels if necessary. For example, thumb(100,100) would convert a 500x400 image to a 100x80 image, then pad it to become a 100x100 image.
DestinationFormat optional string
Format to convert image to. Supported formats are 'jpg', 'png', 'gif', 'bmp', 'tif'. If no format is specified then the image's old format will be used. If the old format is not supported for conversion then it will be converted to a jpeg, assuming that the component is even able to read the image data.
Id mandatory string
Unique identifier for this task.

SQL Call: Store image (mandatory)

Statement to save image. This command is repeated once for every image returned in the command resultset.

May modify database: Yes

Parameters

@Filename string
Name of the converted image. The extension is changed to the requested image type. For example, if you converted 'flowers.bmp' to a jpeg then the filename will be 'flowers.jpg'.
@Id string
Unique identifier for the task.
@Image binary
Converted image

SQL Call: Store metadata (mandatory)

This call is made once for every image that included getMetadata among its commands.

The call is made at the time the command occurs in the command list. That is, for the command string getMetadata;size(100,100) the size of the image before it was resized is returned, where for the command string size(100,100);getMetadata the size after it was resized is returned.

Metadata is returned in the following temp table

CREATE TABLE #Metadata
(
	Width  int NOT NULL,
	Height int NOT NULL,
	DpiX   real NOT NULL,
	DpiY   real NOT NULL
)
May modify database: Yes

Parameters

@Id string
Unique identifier for the task.
@IsMetadata binary
Set to 1 when the StoreMetadata call is performed.

SQL Call: Log error (mandatory)

If converting the image fails then this call is made instead of the Store image call.

May modify database: Yes

Parameters

@ErrorMessage string
The error message.
@Id string
Unique identifier for the task.
@IsError bit
1 when an error occurred.

SQL Call: Validate parameters

Allows you to validate the SQL parameters before any other SQL is run in the component. This call is only made if the SQL is a stored procedure and Validate parameters is checked.

May modify database: No

Parameters

@Force bit
Set to 1 if the last call to validate parameters used admin_force and the user clicked OK in the OK/Cancel dialog.
@ValidateParams bit
Set to 1 when this call is made.

Resultset: Messages (optional)

Table count: repeated zero or one time
Row count: zero or one row
Columns
ADMIN_Force optional string
Message asking the end user to confirm their parameters.
ADMIN_Message optional string
Message explaining why the parameters are rejected.

Custom access control and logging

SQL Call: Custom access control and logging

Use this call to restrict which entries a user is allowed to view and edit, and to log which entries a user views.

Access to a menu item is normally controlled through functions and roles alone but some entities need more fine grained control. For example, a user may have access to the View Member menu item for normal members but not for members with a protected identity.

The menu items a user visits are always logged (in ADMINLogMenuItem) but for sensitive data you may need to log exactly what entries are viewed. Do the logging in this call as the common ways of viewing data (grid and InfoSQL) are not allowed to modify the database.

If you bind a scalar function instead of a stored procedure to this call then its name must end with '_GrantAccess'.

May modify database: Yes

Resultset: Access permissions

Return whether the user is allowed to visit the menu item with the current parameters.
Table count: repeated exactly once
Row count: exactly one row
Columns
GrantAccess mandatory bit
1 if the user is allowed to view the menu item, 0 if the user should not be allowed to view the menu item.

If 0 then an error will be logged as the user should not have been able to reach the menu item with the given parameters in the first place.

Examples

Resizing and converting images

This example is a procedure used by a scheduled job that periodically scans the EmployeePhoto table, converts new photos to JPEG and resizes them to 256x256 pixels.

CREATE OR ALTER PROCEDURE dbo.EmployeePhoto_Resize
    @Command  bit = 0,
    @Id       int = 0,
    @Filename varchar(300) = NULL,
    @Image    varbinary(max) = NULL
AS
BEGIN
    IF @Command = 1
    BEGIN
        SELECT TOP (10)
            EP.EmployeePhotoId AS Id,
            EP.EmployeePhoto,
            EP.EmployeePhotoFilename,
            'thumb(256,256)' AS Command,
            'jpg' AS DestinationFormat
        FROM
            dbo.EmployeePhoto EP
        WHERE
            EP.HasBeenConverted = 0;

        RETURN;
    END;

    IF @Id IS NOT NULL
    BEGIN
        UPDATE dbo.EmployeePhoto SET
            EmployeePhoto         = @Image,
            EmployeePhotoFilename = @Filename,
            HasBeenConverted      = 1
        WHERE
            EmployeePhotoId = @Id;
    END;
END;