[SOLVED] Resizing image using fractional number

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
RyanBram
Posts: 30
Joined: 2013-03-25T22:55:10-07:00
Authentication code: 6789

[SOLVED] Resizing image using fractional number

Post 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
Last edited by RyanBram on 2018-04-25T01:46:34-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing image using fractional number

Post by snibgo »

How about 33.33333%?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resizing image using fractional number

Post 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.
RyanBram
Posts: 30
Joined: 2013-03-25T22:55:10-07:00
Authentication code: 6789

Re: Resizing image using fractional number

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing image using fractional number

Post by snibgo »

That is a feature of IM v7. For Windows, don't escape the percentage with a backslash.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resizing image using fractional number

Post by fmw42 »

RyanBram
Posts: 30
Joined: 2013-03-25T22:55:10-07:00
Authentication code: 6789

Re: Resizing image using fractional number

Post 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?
OS: Windows 7 Ultimate, 32-Bit
CPU: Intel Core i3 2350M @ 2.30GHz
RAM: 2.00 GB Single-Channel DDR3 @ 665MHz
IM Version: 6.8.3-8 2013-03-04 Q16
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing image using fractional number

Post by snibgo »

In Windows BAT, you need to double the % signs: "%%[fx:100/3]%%"
snibgo's IM pages: im.snibgo.com
RyanBram
Posts: 30
Joined: 2013-03-25T22:55:10-07:00
Authentication code: 6789

Re: [SOLVED] Resizing image using fractional number

Post by RyanBram »

It solved.

Thank you very much for your help.
Post Reply