I'm a new user with a photoshop and matlab background. Looking for a imagemagick command to take a image of unknown size and to add white area to it, in order to make the image square.
For example say a user gives me a 1600x900 image or maybe it's 900x1600; I want to add white area to make the final image 1600x1600 while keeping the same pixels in the center.
In photoshop I could issue an expand canvas command with a center option, in matlab I could copy smaller array onto a larger array.
How do you do it in ImageMagick?
Thank you
Looking for Command to Square an Image without Losing Information
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Looking for Command to Square an Image without Losing Information
It's always more helpful if you let us know which version of ImageMagick you're using and which platform or OS you're working on. Your result would be pretty simple to achieve with either IM6 or IM7, but they would be quite different commands.zerp wrote: ↑2017-04-10T08:00:46-07:00I'm a new user with a photoshop and matlab background. Looking for a imagemagick command to take a image of unknown size and to add white area to it, in order to make the image square.
For example say a user gives me a 1600x900 image or maybe it's 900x1600; I want to add white area to make the final image 1600x1600 while keeping the same pixels in the center
Using IM6 from a Windows command prompt, this would do what you want...
Code: Select all
convert input.png -set option:distort:viewport "%[fx:max(w,h)]x%[fx:max(w,h)]" ^
( -clone 0 -distort SRT 0 -fill white -colorize 100 ) +swap -gravity center -composite output.png
Code: Select all
magick input.png -gravity center -background white -extent "%[fx:max(w,h)]x%[fx:max(w,h)]" output.png
Re: Looking for Command to Square an Image without Losing Information
I am using ImageMagick-7.0.5-4-portable-Q16-x86
It would have taken me three days to figure out that command.
Thank you!
It would have taken me three days to figure out that command.
Thank you!