2

I have a bunch of pictures (mostly screenshots, but it doesn't matter) to which I'd like to add a drop shadow. (Reason for it is to add a nice border, as they have white background and I use them on a white background.)

My current workflow is:

  • open the .png file in Inkscape,
  • Filters/Shadow and glow/Drop shadow,
  • select a 3px blur radius, with a 2px 2px offset,
  • export the modified .png.

However, this is done all manually… and it is quite annoying when I have more than… 2 pictures.

I know Inkscape can be used with Command Line Interface (CLI) (I'm on Ubuntu 18.04). I know how to import and export files. However, I don't know how to apply a given filter.

Here's what I've tried, it didn't work:

$ inkscape --verb org.inkscape.effect.filter.ColorDropShadow --verb FileSave --verb FileClose image.png

Hence, could you tell me how to add drop shadow to a picture using CLI?
(This could be done using either Inkscape, or any other open-source software running on Linux)

  • My current progress so far: $ inkscape --verb org.inkscape.effect.filter.ColorDropShadow --verb FileSave --verb FileClose image.png but it is not working. – ebosi Nov 19 '18 at 13:15
  • You might get more out of your your cmd if you used imagamagick instead – joojaa Nov 19 '18 at 17:17
  • You need to export to png, not save. – Moini Nov 19 '18 at 17:27
  • 1
    For this verb a GUI is required as the text output says: WARNING: ignoring verb org.inkscape.effect.filter.ColorDropShadow - GUI required for this verb. – sebix Nov 20 '18 at 20:30
  • 1
    So, to do this properly your script needs to: open the file, select everything in it, apply the noprefs dropshadow filter, then export the selected object to png as a whole (the filter will make it larger, so exporting the page area will not work). – Moini Nov 21 '18 at 1:11
1

Rather than using the vector graphic tool Inkscape I would recommend the ultimate command line tool for bitmap manipulations: ImageMagick.

It should be available through your distribution repositories. This tool comes with many effects, including generating a drop shadow.

This is basically done with the convert -shadow option but you then need to combine the generated background image again with the original. This can all be done in a one-line command using -layers merge option:

convert input.jpg \( +clone -background black -shadow 50x10+15+15 \) +swap -background none -layers merge +repage shadow.png

Useful options for the drop shadow are determined with -background <color> and -shadow percent-opacity{xsigma}{+-}x{+-}y{%}. The example above generates a grey drop shadow with 50% opacity, 10% size and x=+15% y=+15% offset:

enter image description here

Source of above information and more options, and different shadow types see:

  • this is exactly what I'm needing – enabling drop-shadow settings as CLI argument is a real plus. thank you! – ebosi Nov 23 '18 at 10:11
0

Based on Takkat's answer, here is the bash function I have added to my .bashrc:

function dropshadow () {
    filename=$(basename -- "$1")
    # extension="${filename##*.}"
    basename="${filename%.*}"
    # we want to enforce png (even if .jpg as input)
    suffix="_shadow.png"
    convert "$1" \( +clone -background black -shadow 50x10+5+5 \) +swap -background none -layers merge +repage "$basename$suffix"
}
  • Usage: dropshadow <yourfile.ext>,
  • Output: creates <yourfile>_shadow.png in your current working directory.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.