Page 1 of 1

[SOLVED] Resizing image using fractional number

Posted: 2018-04-24T21:01:53-07:00
by RyanBram
As far as I am aware, the -resize command only support natural number or percentage.
I want to resize an image into one-third of its current size. How to achieve this in ImageMagick?

Thanks

Re: Resizing image using fractional number

Posted: 2018-04-24T21:10:57-07:00
by snibgo
How about 33.33333%?

Re: Resizing image using fractional number

Posted: 2018-04-24T23:19:52-07:00
by fmw42
In IM 7 (Unix),

Code: Select all

magick -precision 15 image -resize "%[fx:100/3]\%" result
Please always provide your IM version and platform, since syntax may differ.

Re: Resizing image using fractional number

Posted: 2018-04-24T23:44:10-07:00
by RyanBram
snibgo wrote:
2018-04-24T21:10:57-07:00
How about 33.33333%?
This is my current workaround. But sometimes I feel that I can work faster if I can use fraction directly without need to converting into percentage.
Eg: Sometimes it will get faster if I can set 4/16 instead of 25% or converting it to simplest fraction 1/4.
fmw42 wrote:
2018-04-24T23:19:52-07:00
In IM 7 (Unix),

Code: Select all

magick -precision 15 image -resize "%[fx:100/3]\%" result
Please always provide your IM version and platform, since syntax may differ.
Currently I am using Windows 10 with ImageMagick 7.
Is "%[fx:100/3]\%" a built in math in Unix shell or feature from ImageMagick? If it is a feature of Unix shell, is there any Windows equivalent to get similar result?

Many thanks to all of you.

Re: Resizing image using fractional number

Posted: 2018-04-24T23:59:13-07:00
by snibgo
That is a feature of IM v7. For Windows, don't escape the percentage with a backslash.

Re: Resizing image using fractional number

Posted: 2018-04-25T00:17:48-07:00
by fmw42

Re: Resizing image using fractional number

Posted: 2018-04-25T01:21:24-07:00
by RyanBram
I created a .bat script in Windows with the following command:

Code: Select all

MAGICK -precision 15 input.png -resize "%[fx:100/3]%" output.png
But resulting the following error:
magick.exe: MissingArgument `-resize' at CLI arg 4 @ fatal/magick-cli.c/ProcessCommandOptions/444

What am I doing wrong?

Re: Resizing image using fractional number

Posted: 2018-04-25T01:41:50-07:00
by snibgo
In Windows BAT, you need to double the % signs: "%%[fx:100/3]%%"

Re: [SOLVED] Resizing image using fractional number

Posted: 2018-04-25T01:47:06-07:00
by RyanBram
It solved.

Thank you very much for your help.