How to fade or feather the outer 20pixels to pure white

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
tbayle
Posts: 5
Joined: 2016-11-21T13:18:09-07:00
Authentication code: 1151

How to fade or feather the outer 20pixels to pure white

Post by tbayle »

Starting with a jpg. I want to fade the last 20 pixels on all four edges to white, so when the image is presented on a white background web page you do not see the edge of the image. Need final output to also be jpg if possible.

Here's a link to a dropbox folder with an example image.

https://www.dropbox.com/sh/4mibp578dd4s ... V9Nia?dl=0
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to fade or feather the outer 20pixels to pure white

Post by Bonzo »

You could check out Anthony's examples
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to fade or feather the outer 20pixels to pure white

Post by snibgo »

@tbayle: Your link is broken.

See the recent thread viewtopic.php?f=1&t=30917
snibgo's IM pages: im.snibgo.com
tbayle
Posts: 5
Joined: 2016-11-21T13:18:09-07:00
Authentication code: 1151

Re: How to fade or feather the outer 20pixels to pure white

Post by tbayle »

Not sure what happened to the dropbox link but here's the full address.

https://www.dropbox.com/sh/4mibp578dd4s ... V9Nia?dl=0
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: How to fade or feather the outer 20pixels to pure white

Post by GeeMack »

tbayle wrote:Starting with a jpg. I want to fade the last 20 pixels on all four edges to white, so when the image is presented on a white background web page you do not see the edge of the image. Need final output to also be jpg if possible.
If you want a 20 pixel fade to white on all the edges of your image, you can create a 20 pixel high strip that fades from white to none, then composite that over all four edges of the original. A command like this (with IM 6.9.6 on Windows) will take any size input image...

Code: Select all

convert input.jpg gradient:white-none[1x20!] -background none -virtual-pixel edge ^
   ( -clone 0 -crop x20+0+0 ) ( -clone 0 -crop 20x+0+0 -rotate 90 ) ^
   ( -clone 1-3 +append -distort affine "0,0 %[w],0" )^
   ( -clone 0,4 -composite -rotate 90 -clone 4 -composite -rotate 90 ^
      -clone 4 -composite -rotate 90 -clone 4 -composite -rotate 90 ) ^
   -delete 0--2 -quality 100 output.jpg
It creates a 20 pixel high overlay, longer than either the width or height of the input image, that fades from white to transparent. Then it composites that overlay strip over each edge of the image, one side at a time, by rotating the input and applying the overlay until all four sides are done. Every side of the resulting image fades across exactly 20 pixels and ends in pure white at the outer edge.

If you have a lot of images to process you can use a command like that in a "for" loop.
tbayle
Posts: 5
Joined: 2016-11-21T13:18:09-07:00
Authentication code: 1151

Re: How to fade or feather the outer 20pixels to pure white

Post by tbayle »

I copied your code and created a batch file, but received errors when I ran it.

1. must specify image size 'white-none' @ error/gradient.c/ReadGRADIENTImage/116.
2. invalid argument for option Affine: 'require at least 1 CPs' @ error/distort.c/GenerateCoefficients/466.
3. no such image '-clone' @ error/convert.c/ConvertImageCommand/940.

Also tried doubling up on the % being I'm running it from a batch file but still failed. Running 6.7.2 on windows.

Code: Select all

convert input.jpg gradient:white-none[1x20!] -background none -virtual-pixel edge ^
   ( -clone 0 -crop x20+0+0 ) ( -clone 0 -crop 20x+0+0 -rotate 90 ) ^
   ( -clone 1-3 +append -distort affine "0,0 %[w],0" )^
   ( -clone 0,4 -composite -rotate 90 -clone 4 -composite -rotate 90 ^
      -clone 4 -composite -rotate 90 -clone 4 -composite -rotate 90 ) ^
   -delete 0--2 -quality 100 output.jpg
Post Reply