whugemann wrote:So I tried a command line like
Code: Select all
convert non-scaled.png -resize "%[fx:w*830/450]" scaled.p
ng
but this didn't work.
Actually, I'm trying to do this in a batch file like
Code: Select all
convert %1 -resize "%%[fx:w*%3/%2]" %~n1_scaled%~x1
If I however Identify things first, it works:
Code: Select all
FOR /F %%i IN ('identify -format "%%[fx:w*%3/%2]" %1') DO convert %1 -resize %%i %~n1_scaled%~x1
which seems needlessly complicated. Is this a general limitation or just something in the Windows version? Or is there just something wrong with my Convert command line? The double quotes are needed under Windows, single quote don't work at all.
You have hit on of the MAJOR problems I am battling with for my re-development of the CLI in IMv7.
Basically geometry arguments can not handle percent escapes as it interferes with the normal '%' flag requirements of geometry expressions.
See IM Examples, Basics, Argument Handling
http://www.imagemagick.org/Usage/basics/#arguments
ASIDE: one proposed solution is that % is only thought to be a %expansion : if it is followed by a '[' or is not after a digit
That is
50%x is NOT an expansion, but
50%[x] is while
50%%[ will replace %% with %
The real drawback of allowing % escapes is when DOS is involved! The % character was chosen so as not to interfere with shell (as the development team is essentially UNIX/Linux programmers). Unfortunately it interferes with DOS scripts.
With the above proposal the reduction of any occurrence of %% to % means that in dos to give a read '%' character in a geometry (not following a digit) you would need to use four percents! %%%% (unix shells get the same problem) Arrggghhhh!!!
Another proposal FIX for IMv7, is to restrict the use of % escapes in ALL arguments, except free-form strings.
Such as in
-set as well as
-label,
-comments,
-annotate etc. This will also remove there current use in arguments to
-distort and
-sparse-colors.
However if ANY argument is of the form
%[...] then replace that argument with the pre-calculated escape sequence (doing escape sequence substitutions at that point if a global define).
That is for your specific problem THIS would then work, (in DOS) ...
Code: Select all
-set myresize "%%[fx:w*%3/%2]" -resize "%%[myresize]"
the advantage of this is that it includes 'named' argument. EG this would also work
Code: Select all
-set my_method "Shepards" \
-set my_args "0,0 %[fill] %w,%h %[background]" \
-sparse-colors %[method] %[args]
Why you could then also use percent escapes in
-draw, which is normally not permitted due to SVG compatibility reasons. BUT it can be included only if you follow the above syntax for the draw MVG command argument!
If -set is used escapes would be expanded immediately, and assigned to individual images. But if -define is use the escapes can be expanded WHEN used!
Why it could even be a way of seting up functional macros!
Code: Select all
-define framing_function="-resize 50% -frame 6x6+2+2" \
image.png %[framing_function] result.png
Now that could be useful!
The other solution is to simply replace all % expansions everywhere with some other character -- but that would not be backward compatible, and finding a character is still a problem! Just looking over my keyboard I can see problems for ANY solution.
All proposals are online (update with above shortly) at
http://www.imagemagick.org/Usage/bugs/future/#settings