I'm trying to resize various images using ImageMagick.
I have a requirement for this to be done in a single command without any supporting extra language.
I want to resize all images below a certain width to 115% (or the equivalent: resize all images to a certain size while restricting the maximum enlargement to 115% of the original).
I've tried mixing the different options but it doesn't seem to be supported.
Is this even possible?
I used the distort
operator as a possible solution:
convert in.jpg +distort srt "%[fx:(w<1600)?1.15:1] 0" out.jpg
but when distorting the images >1600 pixels it still does an operation and rewrites the image with a slightly different pixel count.
It might be easier just to use the existing system's commands along with convert
to evaluate the high-level logic.
Example, I'll leverage test utility
test $(identify -format "%[fx:(w<1600)?1:0]" in.jpg) -eq 1 && \
convert in.jpg -resize 115% out.jpg
In ImageMagick 7, the option -exit
will be introduced, so it would be possible to terminate an ImageMagick command if a condition is not meet.
Update
Affine distortion may be a better approach. As the following affine matrix will not alter the image
| 1 0 0 |
| 0 1 0 |
| 0 0 1 |
But the following will resize by 115%
| 1.15 0 0 |
| 0 1.15 0 |
| 0 0 1 |
convert in.jpg +distort AffineProjection \
'%[fx:(w<1600)?1.15:1],0,0,%[fx:(w<1600)?1.15:1],0,0' \
+repage out3.jpg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With