Page 1 of 1
Resize Transparent .png Canvas size & fit viewable image
Posted: 2014-02-10T17:41:24-07:00
by thatfellow
I have a lot of png's that I need to batch convert..
They are all identical canvas size with transparent background..
I need to change the canvas width to 200% & fit the viewable image to new canvas size..
Here is my mission:
a.. create a canvas with transparent background & the correct aspect ratio
b.. apply that background to all .png's scaling viewable image to fit
I can create my Template png with something like this:
Code: Select all
convert -size 440x132 xc:none /path/to/images/Background.png
I can trim all png's to actual viewable size with something like this:
Code: Select all
mogrify -path /path/to/images -format png -trim *.png
I now need to apply new canvas Template (Background.png) to all images scaling viewable area to best fit. (This is where I get lost)
Also, there might be an much easier way to do this all in one go within mogrify so please feel free to correct & suggest as I am very new to this excellent software..
Thankyou
Re: Resize Transparent .png Canvas size & fit viewable image
Posted: 2014-02-10T18:24:13-07:00
by snibgo
Don't worry about creating a template. It probably isn't needed.
I don't understand what you want to happen to your images. "I need to change the canvas width to 200% & fit the viewable image to new canvas size.." (which is 440x132, right?)
Perhaps you mean that all your images are smaller then 440x132, and you want to enlarge them to fit entirely within a box 440x132 and then, if needed, expand the image vertically or horizontally to be exactly 440x132.
Or perhaps you want expand the image to 200% horizontally (and not vertically), then do something else.
Re: Resize Transparent .png Canvas size & fit viewable image
Posted: 2014-02-10T18:26:38-07:00
by fmw42
try
create new folder2 (to avoid writing over your original images)
assume images are in folder1
cd path2/folder1
mogrify -path path2/folder2 -format png -trim +repage -background none -resize 200% -extent -extent 200x200% *.png
That should avoid the need to create a new background image.
see
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/thumbnails/#pad
http://www.imagemagick.org/Usage/crop/#extent
This assumes you want to trim out the old transparent background, resize what is left to 200% and pad with transparency when the aspect ratio does not match
Re: Resize Transparent .png Canvas size & fit viewable image
Posted: 2014-02-10T20:54:53-07:00
by thatfellow
@ snibgo
Yes, all images are currently 220x132 and I will want to double the width & preserve the height, so new image will be 440x132.
Then I will want to expand the viewable image to the new 440x132 extents (Centering the image on new canvas).
@fmw42
create new folder2 (to avoid writing over your original images)
assume images are in folder1
cd path2/folder1
mogrify -path path2/folder2 -format png -trim +repage -background none -resize 200% -extent -extent 200x200% *.png
That should avoid the need to create a new background image.
This assumes you want to trim out the old transparent background, resize what is left to 200% and pad with transparency when the aspect ratio does not match
I tried that fmw42 but resize did not seem to work and the results were a bit hit & miss..
I think I will stick to fitting the trimmed images to the background template..
Can you suggest a line to insert background.png to all the trimmed images keeping their filenames & resizing viewable image to be centered & fit background.png extents?
Thankyou
Re: Resize Transparent .png Canvas size & fit viewable image
Posted: 2014-02-10T22:52:16-07:00
by fmw42
try
mogrify -path path2/folder2 -format png -trim +repage -background none -resize 440x132 -extent -extent 440x132 *.png
Re: Resize Transparent .png Canvas size & fit viewable image
Posted: 2014-02-11T08:44:27-07:00
by thatfellow
That worked perfectly, the only problem is that the pics are not all centered on the x & Y
Re: Resize Transparent .png Canvas size & fit viewable image
Posted: 2014-02-11T09:11:54-07:00
by snibgo
You probably need "-gravity center" before "-extent". (And only one "-extent.)
Re: Resize Transparent .png Canvas size & fit viewable image
Posted: 2014-02-11T11:26:30-07:00
by fmw42
snibgo wrote:You probably need "-gravity center" before "-extent". (And only one "-extent.)
Yes, I forgot about that. Thanks snibgo.