Keep Aspect Ratio on Resize and Fill with Blur Background
Keep Aspect Ratio on Resize and Fill with Blur Background
Hi everyone,
I need to resize a lot images with different sizes to a uniform size, while keeping the aspect ratio of each image. But instead of a single color background, I would like to use a blur version of the original image as background. Here is an example, how it should look like:
http://i.imgur.com/wmseTZp.png
How can I implement this with ImageMagick?
Cheers
x
I need to resize a lot images with different sizes to a uniform size, while keeping the aspect ratio of each image. But instead of a single color background, I would like to use a blur version of the original image as background. Here is an example, how it should look like:
http://i.imgur.com/wmseTZp.png
How can I implement this with ImageMagick?
Cheers
x
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
Create your blurred image, then resize the original and composite it over the center of the blurred image.
Unix syntax:
Please always provide your version of IM and platform when asking questions. Syntax may differ on unix and windows systems.
Unix syntax:
Code: Select all
convert image \( -clone 0 -blur 0xsigma \) \( -clone 0 -resize WxH \) \
-delete 0 -gravity center -compose over -composite result
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
Thanks! This is what I was looking for:
Code: Select all
convert source.png \( -clone 0 -blur 0x9-resize WxH\! \) \( -clone 0 -resize WxH \) \
-delete 0 -gravity center -compose over -composite result.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
You must put in real numbers for WxH. Also you need a space between -blur 0x9 and -resize.convert source.png \( -clone 0 -blur 0x9-resize WxH\! \) \( -clone 0 -resize WxH \) \
-delete 0 -gravity center -compose over -composite result.png
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
Hello guys, am new to image magic but this thread describes exactly what I want to do with a bunch of images at once. The challenge is I managed to install image magic (first option from this link "http://www.imagemagick.org/script/binar ... hp#windows") but I don't know how to carry on with the script thing. I created a notepad, copied the script into it and saved it as a .bat file in the folder which contains the images I want to convert, but all I get is errors when I run the .bat file. Please any help on how to get my images resized to 4:3 but keeping aspect ratio of original and using a blurred orginal as background? Am running a windows 8 OS
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
Please don't multi-post. I've removed your other post.
What is in your BAT file? What error messages do you get?
The commands given above are for bash, not Windows BAT. For BAT, change the end-of-line markers from \ to ^, and remove the back-slashes before parentheses ( and ).
What is in your BAT file? What error messages do you get?
The commands given above are for bash, not Windows BAT. For BAT, change the end-of-line markers from \ to ^, and remove the back-slashes before parentheses ( and ).
snibgo's IM pages: im.snibgo.com
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
Sorry for the multiple post anyway. Now I did change the code from
convert source.png \( -clone 0 -blur 0x9-resize WxH\! \) \( -clone 0 -resize WxH \) \
-delete 0 -gravity center -compose over -composite result.png
to
convert source.png ^( -clone 0 -blur 0x9-resize WxH\! ) ^( -clone 0 -resize WxH ) ^
-delete 0 -gravity center -compose over -composite result.png
but it didn't work, I suppose I didn't do the changes right. I also tried this code too
if not exist "%~dp1output" md "%~dp1output"
for %%f in ("%~dp1*.jpg" "%~dp1*.jpeg" "%~dp1*.png") do convert "%%f" ( +clone -geometry x1080 ) ( -clone 0 -geometry 1920x -gravity center -crop 1920x1080+0+0 -blur 0x8 ) -delete 0 +swap -gravity center -compose over -composite "output\%%~nf_1080.jpg"
as described on this page (https://www.reddit.com/r/software/comme ... ackground/) but when I ran the .bat file which I created, I got "Invalid parameter" error
If it could help, how about we picture a folder on Desktop (windows 8 64bit) containing pictures. How do I carry the aforementioned process on them? I already have image magic (first option from this link "http://www.imagemagick.org/script/binar ... hp#windows") installed. Your thoughts are most welcomed
convert source.png \( -clone 0 -blur 0x9-resize WxH\! \) \( -clone 0 -resize WxH \) \
-delete 0 -gravity center -compose over -composite result.png
to
convert source.png ^( -clone 0 -blur 0x9-resize WxH\! ) ^( -clone 0 -resize WxH ) ^
-delete 0 -gravity center -compose over -composite result.png
but it didn't work, I suppose I didn't do the changes right. I also tried this code too
if not exist "%~dp1output" md "%~dp1output"
for %%f in ("%~dp1*.jpg" "%~dp1*.jpeg" "%~dp1*.png") do convert "%%f" ( +clone -geometry x1080 ) ( -clone 0 -geometry 1920x -gravity center -crop 1920x1080+0+0 -blur 0x8 ) -delete 0 +swap -gravity center -compose over -composite "output\%%~nf_1080.jpg"
as described on this page (https://www.reddit.com/r/software/comme ... ackground/) but when I ran the .bat file which I created, I got "Invalid parameter" error
If it could help, how about we picture a folder on Desktop (windows 8 64bit) containing pictures. How do I carry the aforementioned process on them? I already have image magic (first option from this link "http://www.imagemagick.org/script/binar ... hp#windows") installed. Your thoughts are most welcomed
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
Try
or perhaps
Where you replace W and H with your desired width and height
Code: Select all
convert source.png ( -clone 0 -blur 0x9 -resize WxH^! ) ( -clone 0 -resize WxH ) -delete 0 -gravity center -compose over -composite result.png
Code: Select all
convert source.png ( -clone 0 -blur 0x9 -resize "WxH!" ) ( -clone 0 -resize WxH ) -delete 0 -gravity center -compose over -composite result.png
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
First, the "Invalid Parameter" error indicates your command is using the Windows "convert" command. If you installed ImageMagick v6 you'll have to call your ImageMagick "convert" using its full path or add its path to your PATH statement in the Windows settings. If you installed ImageMagick v7 you won't use the "convert" command. Instead you'll use "magick".Sweetins wrote: ↑2017-06-28T09:41:05-07:00... but when I ran the .bat file which I created, I got "Invalid parameter" error
If it could help, how about we picture a folder on Desktop (windows 8 64bit) containing pictures. How do I carry the aforementioned process on them? I already have image magic (first option from this link "http://www.imagemagick.org/script/binar ... hp#windows") installed. Your thoughts are most welcomed
Once you are accessing the correct "convert" or "magick" command, you'll have to give some values to those W's and H's. I usually use WIDE and HIGH instead of single letters as variable names because it's easier for me to keep track of them. So at a command line or in a BAT script you need to do something like this...
Code: Select all
set WIDE=1920
set HIGH=1080
convert source.png ^( -clone 0 -blur 0x9 -resize %WIDE%x%HIGH%^! ^) ^
-resize %WIDE%x%HIGH% +swap -gravity center -compose over -composite result.png
Code: Select all
convert source.png ^( -clone 0 -blur 0x9 -resize 1920x1080^! ^) ^
-resize 1920x1080 +swap -gravity center -compose over -composite result.png
Last edited by GeeMack on 2017-06-28T10:12:31-07:00, edited 1 time in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
As GeeMack says, that's a big clue. Does "convert" work from the command line? Like this:... I got "Invalid parameter" error.
Code: Select all
convert rose: r.png
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
@Geemack -- don't you need to double the % in a bat file?
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
Variables that are set like "set WIDE=1920" can be accessed even in a BAT script with a percent sign on each end like "%WIDE%". Other uses of percent signs like for FX expressions or the single letter variables used inside a FOR loop must be doubled in a BAT script, like "... %%[fx:h/2] ..."
It's Windows. It's not supposed to be understandable.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
@Geemack -- thanks for explanation to a purely Unix syntax user.
Re: Keep Aspect Ratio on Resize and Fill with Blur Background
Sure thing guys, changing the "convert" command to "magick" did solve the problem. Thanks so much