extent one dimension

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
leo

extent one dimension

Post by leo »

Dear all,

I'd like to extent an image in only one dimension to a fixed size while the 2nd dimension should be left untouched.
Examples:

400x400 => 400x1000
300x600 => 300x1000
800x200 => 800x1000
(gravity south)

I tried a lot of things using -extent +/-(re)page, -splice and -crop but for some reasons couldn't get it working.
convert does not like -extent x1000, really uses a width of 0 pixels then, causing an error.
I often use ImageMagick and like it very much. Please provide me with an example, I'm stuck somehow.

Best,
Leander
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: extent one dimension

Post by fmw42 »

extent works by telling it what dimensions you want achieve. So if you want to preserve one dimension, then you still have to say what the value is that you want to preserve. So if the image is 100x200 and you want to make it 200x200, you have to say -extent 200x200. In other words, you have to know how big the image is in the dimension you want to preserve.

You can do that by extracting the dimension from the image, first then using that for -extent. So lets say you want to double the width and keep the height and have it centered, then

newwidth=`convert image -format "%[fx:2*w]" info:`
height=`convert image -format "%h" info:`
convert image -gravity center -background black -extent ${newwidth}x${height} result

If you want to tell a command how much to add rather than the size, then you can do that on only one dimension with the -border command. So if you want to add 50 to each horizontal side, but leave the vertical the same

convert image -bordercolor black -border 50x0 result
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: extent one dimension

Post by magick »

In other words, you have to know how big the image is in the dimension you want to preserve.
We have a patch in the Subversion trunk to support geometries like x1000 which says to preserve the image width and extend the image height to 1000 pixels.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: extent one dimension

Post by fmw42 »

great! nice addition
leo

Re: extent one dimension

Post by leo »

fmw42 wrote:height=`convert image -format "%h" info:`
yes, that's how I'm doing it now, using a little shellscript to work around it. thank you!
magick wrote: We have a patch in the Subversion trunk to support geometries like x1000 which says to preserve the image width and extend the image height to 1000 pixels.
thats great, I guess it will be avaiblable in future stable releases? thanks,

Best,
Leo
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: extent one dimension

Post by anthony »

Unfortunately that patch BROKE -splice, -chop -border, and quite a few other things, as such the patch that was put into place has now been backed out. :roll:

As such until someone can get to a adding it directly and correctly into the Extent operator itself, it will not be available. :?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply