cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
hogi
Level XII

crop image and store into new column

I wanted to crop images and store the cropped images in a new column.

My first approach was:

for each row (:new col = :old col << crop(...))

 ... but then I found @Craige_Hales post in the the community,
https://community.jmp.com/t5/Discussions/Crop-a-JPG-Image/m-p/442473/highlight/true#M69072 
 with the important information:
hogi_1-1744966224479.png

So, I tried this:

Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
for each row (:pet = :picture );
wait(0);
for each row (:pet <<  Crop( Left( 5 ), Right( 10 ), Top( 6 ), Bottom( 100 ) ));

... without effect.

 

 

In the Scripting Index, I found:

hogi_2-1744967075102.png

Maybe use img as a temporary variable?

Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
for each row( img= :picture;;img  <<   Crop( Left( 5 ), Right( 70 ), Top( 30 ), Bottom( 50 ) );:pet = img)

and indeed:

hogi_3-1744967420011.png

But after clicking into the data table, I noticed that the input column was changed as well:

hogi_4-1744967455266.png



so, my final script was:

Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
for each row( img= new image(:picture);img  <<   Crop( Left( 5 ), Right( 70 ), Top( 30 ), Bottom( 50 ) );:pet = img)
  • use new image() to create a new image
  • resize this image
  • store it in the new column
1 ACCEPTED SOLUTION

Accepted Solutions
hogi
Level XII

Re: crop image and store into new column

Unfortunately, with my actual data set, just some of the images got cropped.

 

The easy explanation:  I filled the image column  via copy / paste from a Powerpoint presentation.
All the images had the same aspect ratio, therefore they had the same size in the JMP data grid -  but they did not have the same actual size! And crop just works if the pixel values in the arguments are smaller than the actual size of the image.


Much easier to detect, when you use images with different aspect ratios ( trying to create a demo case for a community post ).

hogi_0-1744969643296.png

Open( "$SAMPLE_DATA/SAS Offices.jmp" );
New Column( "cropped", Expression);

for each row( img= new image(:Photo);
{w, h} = img << Get Size;

img  <<   Crop( Left( 10 ), Right( 800 ), Top( 10 ), Bottom( 70 ) );:cropped = img)  

 
so, my final script was:

Open( "$SAMPLE_DATA/SAS Offices.jmp" );
New Column( "cropped", Expression );

For Each Row(
	try(img = New Image( :Photo );
	{w, h} = img << Get Size;
	target = 500;
	img << scale( 500 / w );
	{w, h} = img << Get Size;
	img << Crop( Left( Round( w / 3 ) ), Right( Round( w / 3 * 2 ) ), Top( Round( h / 10 ) ), Bottom( Round( h / 5 ) ) );
	:cropped = img;)
);

Try? -> just in case one of the images is missing.

View solution in original post

3 REPLIES 3
hogi
Level XII

Re: crop image and store into new column

Unfortunately, with my actual data set, just some of the images got cropped.

 

The easy explanation:  I filled the image column  via copy / paste from a Powerpoint presentation.
All the images had the same aspect ratio, therefore they had the same size in the JMP data grid -  but they did not have the same actual size! And crop just works if the pixel values in the arguments are smaller than the actual size of the image.


Much easier to detect, when you use images with different aspect ratios ( trying to create a demo case for a community post ).

hogi_0-1744969643296.png

Open( "$SAMPLE_DATA/SAS Offices.jmp" );
New Column( "cropped", Expression);

for each row( img= new image(:Photo);
{w, h} = img << Get Size;

img  <<   Crop( Left( 10 ), Right( 800 ), Top( 10 ), Bottom( 70 ) );:cropped = img)  

 
so, my final script was:

Open( "$SAMPLE_DATA/SAS Offices.jmp" );
New Column( "cropped", Expression );

For Each Row(
	try(img = New Image( :Photo );
	{w, h} = img << Get Size;
	target = 500;
	img << scale( 500 / w );
	{w, h} = img << Get Size;
	img << Crop( Left( Round( w / 3 ) ), Right( Round( w / 3 * 2 ) ), Top( Round( h / 10 ) ), Bottom( Round( h / 5 ) ) );
	:cropped = img;)
);

Try? -> just in case one of the images is missing.

lala
Level VIII

Re: crop image and store into new column

This is not difficult.

I think the difficult part is: making the background of one picture transparent and superimposing it on other pictures.

JSL does not have the function of making the background of pictures transparent.

It can only be achieved with the assistance of other software

lala
Level VIII

Re: crop image and store into new column

run program(executable("I:\00\FastStoneIV\magick.exe"),options({目||" -fill none -fuzz 0% -draw \!"color 92,30 floodfill\!" "||标}));

2025-04-18_18-22-01.png

Recommended Articles