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?".
bwroga
Posts: 9 Joined: 2019-04-27T12:45:45-07:00
Authentication code: 1152
Contact:
Post
by bwroga » 2019-05-03T15:49:40-07:00
Is it possible to use percent escapes with the -extent option?
I would like to swap the width and height of an image, but keep everything else the same.
I tried all of the following:
Code: Select all
convert a.png -extent %hx%w d.png
convert a.png -extent '%hx%w' d.png
convert a.png -extent '%[h]x%[w]' d.png
convert a.png -extent '%[fx:h*1]x%[fx:w*1]' d.png
but I get invalid argument errors for each.
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Contact:
Post
by fmw42 » 2019-05-03T15:55:24-07:00
Only in IM 7.
Should be OK, but system dependent whether quotes are needed and may require double quotes.
Code: Select all
magick a.png -extent %hx%w d.png
magick a.png -extent '%hx%w' d.png
This is not allowed syntax:
Code: Select all
magick a.png -extent '%[h]x%[w]' d.png
No need to multiply by 1 in this syntax:
Code: Select all
magick a.png -extent '%[fx:h*1]x%[fx:w*1]' d.png
snibgo
Posts: 12159 Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Contact:
Post
by snibgo » 2019-05-03T16:05:01-07:00
As Fred says, only with IM v7. Ensure you are using v7, and use "magick", not "convert".
GeeMack
Posts: 718 Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA
Contact:
Post
by GeeMack » 2019-05-03T16:16:58-07:00
bwroga wrote: 2019-05-03T15:49:40-07:00 Is it possible to use percent escapes with the -extent option?
I would like to swap the width and height of an image, but keep everything else the same.
As mentioned, the FX expressions are most versatile using IM7, but it can be done with IM6 using "-distort" and setting a viewport. Try this...
Code: Select all
convert a.png -set option:distort:viewport %[h]x%[w] -virtual-pixel none \
-distort affine "%[fx:w/2],%[fx:h/2] %[fx:h/2],%[fx:w/2]" result.png
There are many options available for that virtual-pixel setting, which defines what IM does with the space not filled with any image after the distort. I used "none" which leaves a transparent background. You could use "black" or "white" or set a background color and use "-virtual-pixel background".
bwroga
Posts: 9 Joined: 2019-04-27T12:45:45-07:00
Authentication code: 1152
Contact:
Post
by bwroga » 2019-05-03T16:30:23-07:00
I think I'll go ahead and upgrade, I was using 6.9.7-4. Thank you everyone.
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Contact:
Post
by fmw42 » 2019-05-03T16:31:47-07:00
Just to be clear, GeeMack is providing an IM 6 alternative that does the same as -extent (though not as straight-forward), but using -distort Affine. In IM7 6, you can only use % escapes in a few functions including -distort, but not -extent.
Users browsing this forum: Amazon [Bot] , Google [Bot] , Semrush [Bot] and 48 guests