Regular expression to determine ratio image with conditions

Post Reply
ChritianK
Member
Posts: 43
Joined: Wed Nov 29, 2017 10:57 am

Regular expression to determine ratio image with conditions

Post by ChritianK »

Hello,
I need a little help if it is possible to do this :
- Have a flow that check orientation of images : landscape or portrait then resize homothetic image to specific dimension for Magento webfile : 1000x1640 px for portrait, or 1640x1000 px for landscape orientation

Condition : width < height => portrait then resize height to 1640 px, and crop center width to 1000 px
or width > height => landscape then resize width to 1000 px, and crop center height to 1640 px


Sometimes have images that ratio is not compatible with output format :
image is portrait orientation but the width is too small so I cannot use the script to crop for portrait dimension, but use the landscape setting.

for example have this image 3129x6569 px
width<height so portrait, resize 6569 px to 1640, ok but the width is 804 px... so I can't have 1000x1640 px

In fact, I have to ensure that ratio width/height is superior than 60% in my case.If not, first resize the width than crop center the height.

My flow works great to determine orientation, resize and crop center, I just need help to specify condition to the connector : is there a way to have a connection with a regular expression can do it ? but I didn't know how to write this condition in regex : width/height>60%
or if it is possible to do it :-)
Best Regards,
Christian
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Regular expression to determine ratio image with conditions

Post by freddyp »

You have to use Switch - Calculation in the left-hand part of the condition in which you do the math using variables, and the operator will be "Greater than" and the right-hand part is 60. The left-hand part of your condition will look something like this:

Code: Select all

[Switch.Calculation:Expression="([Image.ImageWidth] / [Image.ImageLength]) * 100"]
ChritianK
Member
Posts: 43
Joined: Wed Nov 29, 2017 10:57 am

Re: Regular expression to determine ratio image with conditions

Post by ChritianK »

Thanks for prompt answer freddy !
I'm testing it and give feedback !
ChritianK
Member
Posts: 43
Joined: Wed Nov 29, 2017 10:57 am

Re: Regular expression to determine ratio image with conditions

Post by ChritianK »

Many many thanks, it works great !
Thanks for your help !
Christian
Post Reply