Sorting images based on portrait and landscape

Post Reply
User avatar
JimmyHartington
Advanced member
Posts: 305
Joined: Tue Mar 22, 2011 7:38 am

Sorting images based on portrait and landscape

Post by JimmyHartington »

I have tried to make a script expression, which should make all portrait (and square images) move through the connection on which this expression is set.



This is my expression:

// Moves portrait images through connection

var x = photo.getPixelXDimension();

var y = photo.getPixelYDimension();



x / y >= 1;



And it does not work.



Probably because the photo.getPixelXDimension() is not correct.



Is there a place to look up the different options I have for getting information about a file?



I have used the variables alot and would hope I had the same options in javascript.
rzacherl
Member
Posts: 38
Joined: Mon Mar 21, 2011 3:29 pm

Sorting images based on portrait and landscape

Post by rzacherl »

Hi Jimmy,



it seems as if you try to make use of the PixelXDimension and PixelYDimension variables from the Switch Photo variable group.

As Switch variables are no JavaScript objects they can't be instantiated and do not offer functions to return their value.

Instead you have to use the getVariableAs...() methods of the Job class.



To store the number of image pixels per row in a JavaScript variable named x you would use the folling code:



var x = job.getVariableAsNumber( "[Photo.PixelXDimension]" );



It can be dangerous to rely purely on the metadata of an image as you do (you're using values from the EXIF metadata). Dangerous because the image could have been already changed and the processing piece of software might have not updated the EXIF information correctly).

Therefore as long as only TIFF, JPEG or PNG images are used, you should use the [Stats.PixelXDimension] and [Stats.PixelYDimension variables instead because here the image data is analyzed directly by Switch.





Kind regards,



Robert
User avatar
JimmyHartington
Advanced member
Posts: 305
Joined: Tue Mar 22, 2011 7:38 am

Sorting images based on portrait and landscape

Post by JimmyHartington »

Hi Robert



Thanks for the reply.



I have now modified the script expression accordingly:

// Moves portrait images through connection

var x = job.getVariableAsNumber( "[Stats.PixelXDimension]" );

var y = job.getVariableAsNumber( "[Stats.PixelYDimension]" );



x / y <= 1;





And it works.



I can see your the danger in using the EXIF data.



Thanks again.



Kind regards

Jimmy Hartington
Post Reply