<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />I'm currently running a script that inserts a 1Mb image into a data table using the following simple script ( where :link to image is a network drive where the jpg is stored)
Formula( Open( :Link to Image, "jpg" ) ),
Due to the size of the image the data table is getting large ( I have ~1500 images) and have tried the crop function but cannot get the syntax correct
one of the various ways I have tried is the following ( and probably all combinations of this apart from the correct one!).
Formula( Open( :Link to Image, "jpg" ) ) << crop( Left( 190 ), top( 0 ), bottom( 1690 ), Right( 700 ) ),
I feel I'm close but not quite there.
Ideally it would do the following
- Open the image ( one at a time to save computer memory?)
- crop the image, then save the crop into a central folder. This would then allow for additional image analysis if required.
- Insert the crop into the data table
- Close the original image.
Regards
David
Here is an example script that does what you indicated you wanted
Names Default To Here( 1 );
// Get the list of the pictures
filelist = Files In Directory( "$SAMPLE_IMAGES" );
// Loop across all of the pictures, cropping and saving
For( i = 1, i <= N Items( filelist ), i++,
// Using a Substitute because the extension value needs to be an expression,
// not a literal
Eval(
Substitute(
Expr(
img = Open( "$SAMPLE_IMAGES\" || filelist[i], __extension__ )
),
Expr( __extension__ ), Parse( Word( -1, filelist[i], "." ) )
)
);
// Allow time for the image to be read
Wait( 1 );
// Crop the image
img << Crop( Left( 50 ), Right( 100 ), Top( 60 ), Bottom( 150 ) );
// Save the image to a new folder
img << Save Picture( "" || filelist[i], Word( -1, filelist[i], "." ) );
);
// Create a new table
New Table( "Untitled",
Add Rows( N Items( filelist ) ),
New Column( "image", Expression, "None", Set Values( {} ) )
);
// Populate the image column
foreachrow(
:image = newimage("" || filelist[row()])
);