DMXzone Image Processor Support Product Page


How do I crop an image to a square if I don't know if it's landscape or portrait or its dimensions?

Asked 24 May 2017 13:46:21
has this question
24 May 2017 13:46:21 Bruce Wilkie posted:
Hi there

I'm uploading an image and resizing it fine. I now want to create a square thumbnail of the image. The original could be landscape or portrait and I won't know the dimensions. How do I only crop off the top and bottom if it's portrait, or only crop off the left and right if it's landscape, to make it a square, and then shrink it down to a thumbnail?

In the tutorial video I can create a square by setting the dimensions when cropping, but because I don't know the dimensions of the original don't know how big to make the square when cropping (should be the same size as the smallest of either the width or the height)?

Thanks in advance


Replied 25 May 2017 08:13:49
25 May 2017 08:13:49 Teodor Kuduschiev replied:
Hello Bruce,
Do you have some kind of validation applied for min image dimensions?
Replied 25 May 2017 10:07:05
25 May 2017 10:07:05 Bruce Wilkie replied:
Hi Teodor

Do you mean setting a minimum size of image when uploading?

If so, then no. I’ve not tried anything beyond adapting the video tutorial on resizing and creating a thumbnail at so that when it created the thumbnail it crops it into a square at the same time.

With DMXZone Smart Image Processor I could just tick a box labelled ‘Crop to Fit’ when resizing and so long as I set the height and width to be the same then it would shrink it first and then crop it into a square.

Is there a quick way of doing this in DMXZone Image Processor?

I’ve looked at adding a condition that says something like ‘if width is more than height then crop width equal to (get value of height of image), else crop height equal to (get width). But I’ve not got that to work yet.

Replied 25 May 2017 15:00:59
25 May 2017 15:00:59 Teodor Kuduschiev replied:
Hi Bruce,
I got your idea - will check what's the best way of doing this and will let you know.
Replied 26 May 2017 11:08:44
26 May 2017 11:08:44 Bruce Wilkie replied:
Thanks Teodor.

I'm still working on this myself to see if I can find a way of doing this.

Seems like conditions could well help me, but when I look into it more I cant find anything in the manuals to help me, and let me know how do I write conditions?

I can only find one reference to them so far in a tutorial video at

But in that video it only enters a single value so it looks like a boolean 'if it exists' condition. I'm wanting to check if the height of an image is greater than the width.

I've entered the following into the condition field: "if {{imageInfo1.height}} > {{imageInfo1.width}}"

Is that the right way to do it? I have to type this in manually as clicking on the lightning symbol only allows me to click on a single entity. Clicking on a second overwrites whatever is already entered.

Is there a part of the manual that teaches us how to use conditions? If not could you let me know?

I can send you a screenshot? How do I do that here?

Replied 26 May 2017 11:35:18
26 May 2017 11:35:18 Bruce Wilkie replied:
OK, I've figured it conditions now. And with that managed to find the solution to my original question.

So, for Conditions I was really close. I just had to leave out 'if' in the condition field.

So, Iput it like this:

Get Image Size
Condition: "{{imageInfo1.width}} > {{imageInfo1.height}}"
Then: Crop Image
Width: "{{imageInfo1.height}}"
Height: "{{imageInfo1.height}}"
Else: Crop Image
Width: "{{imageInfo1.width}}"
Height: "{{imageInfo1.height}}"

Hope that makes sense to anyone else looking for how to crop to a square. If there is a quicker way like the old checkbox from Smart Image Processor then please do let me know and I'll update this.

Replied 27 May 2017 09:03:33
27 May 2017 09:03:33 Teodor Kuduschiev replied:
Hi Bruce,
That is indeed the way to go, everything is well as you defined it.
Replied 30 Jul 2017 11:02:07
30 Jul 2017 11:02:07 Greta Garberini replied:
Hi, thanks for this.

Would'nt it be correct to crop both times the width of the photo if it is a portrait ?

I have a very similar problem.
I want to crop the picture to a size of 300x200 px, but depending on portrait or landscape I want to rotate it to the right first if it consists of a portrait format. Most photos are landscape but there are also some pictures of bottles which use portrait format so I used a condition like
({{width}}/{{height}} < 1) 

and used brackets instead of "" simply because I did not know the correct syntax. Is there any description of this? (brackets worked for me)
Now I need a second condition: Only if the category of the pictures are "bottles" then rotate. Do not rotate a picture of a tree from another category even if it is a portrait format. This does not work. As I said, I am unsure what syntax is used to achieve this.

Reply to this topic