Gallerymagick - resize image setting only target width


I am using gallery magick library to resize the original image.
It is working fine except some images in which I would only like to set the width to 900px and calculate the height proportionally.
If I call the method ScalrProcessorUtils.resizeImage(ContentFileObjectUtils.toFile(sourceFile), ContentFileObjectUtils.toFile(targetFile), dimension);
By passing as dimension 900x0 , I get the final image resized to 1x1

This is probably because in there is

targetHeight = Math.round((float) targetWidth * ratio);

which sets also the targetHeight to 0

Is there a more proper way to set the dimension instead of 900x0 or is there something to be fixed?

Thank you,



More investigations lead me to think that this issue occours only when we have vertical images (height > width) and we want a proportional resize by passing only the width and the height to zero.

I think that I found out the issue: in ScalrProcessorUtils class of GalleryMagick library there is a static method which calls Scalr class of imgscalr library with the hardcoded Mode.AUTOMATIC mode, while it should be configurable.
In our case, it has to be Mode.FIT_TO_WIDTH

BufferedImage resizedImage = Scalr.resize(sourceImage, Method.QUALITY, Mode.AUTOMATIC, dimension.getWidth(), dimension.getHeight(), new BufferedImageOp[0]);

Can it be fixed?


Hi Flavio,

Sounds like a good improvement to change the mode somehow.
It’s a community-driven forge project. So, PRs are welcome! :wink:


1 Like

Nice digging :smile:

You’re referring to the plugin at, correct?
Class org.onehippo.forge.gallerymagick.core.command.ScalrProcessorUtils calling org.imgscalr.Scalr.resize?

There’s already some logic if (dimension.getHeight() == 0) { mode = Scalr.Mode.FIT_TO_WIDTH; } in versions 3.0.1 and 2.0.2, see

Hope this helps

1 Like

Thank you both for your answers!