Discard original image when making shadow

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
mikewhy
Posts: 2
Joined: 2015-12-10T11:28:41-07:00
Authentication code: 1151

Discard original image when making shadow

Post by mikewhy »

I'm trying to use `convert` to generate glow images for a game we are working on.

I've got most of the command done already

Code: Select all

[ ! -f input.png ] && curl -L http://bellard.org/bpg/2.png --output input.png
 
convert \
  input.png \
  -background none \
  \( +clone -background \#f0f -shadow 100x40 -channel A -level 0,70% +channel \) \
  -background none \
  +swap \
  +repage \
  -shave 80 \
  output.png
The issues is that outputs `output-0.png` and `output-1.png`, where I need `output-0.png` to really be `output.png`.

I know I can just use anything to remove the unnecessary `output-1.png` and rename the other file, but is there a way to do this in imagemagick?

Using `-layers merge` allows the original image to seep through, which we don't want and will make the file size larger.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Discard original image when making shadow

Post by fmw42 »

convert \
input.png \
-background none \
\( +clone -background \#f0f -shadow 100x40 -channel A -level 0,70% +channel \) \
-background none \
+swap \
+repage \
-shave 80 \
output.png
I believe you left out -layers merge

Code: Select all

convert \
  input.png \
  \( +clone -background \#f0f -shadow 100x40 -channel A -level 0,70% +channel \) \
  -background none \
  +swap \
  -background none \
  -layers merge \
  +repage \
  -shave 80 \
  output.png
see http://www.imagemagick.org/Usage/blur/#shadow
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Discard original image when making shadow

Post by Bonzo »

From the way I read the post fmw42 the OP just wants the shadow without the original image and does not need the additional layer number.

Something like this?

Code: Select all

convert.exe input.png ( +clone -background "#f0f" -shadow 100x40 -channel A -level 0,70% +channel ) -background none -delete 0 +repage -shave 80 output.png
Last edited by Bonzo on 2015-12-10T12:33:01-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Discard original image when making shadow

Post by fmw42 »

Bonzo wrote:From the way I read the post fmw42 the OP just wants the shadow without the original image and does not need the additional layer number.
OK. Perhaps I misunderstood. Try

Code: Select all

convert \
input.png \
\( +clone -background \#f0f -shadow 100x40 -channel A -level 0,70% +channel \) \
-delete 0
-shave 80 \
output.png
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Discard original image when making shadow

Post by Bonzo »

Just edited my post as you were posting fmw42
mikewhy
Posts: 2
Joined: 2015-12-10T11:28:41-07:00
Authentication code: 1151

Re: Discard original image when making shadow

Post by mikewhy »

`delete 0` is exactly what I am looking for, thanks so much! Here's the final command, for posterity:

Code: Select all

convert \
    input.png \
    \( +clone -background \#f0f -shadow 100x20 -channel A -level 0,70% +channel \) \
    -delete 0 \
    -shave 40 \
    output.png
aka exactly what fmw42 posted.
Post Reply