DEV Community

Cover image for How to make super duper shadows for your screenshots
Corentin Bettiol
Corentin Bettiol

Posted on • Updated on

How to make super duper shadows for your screenshots

screenshot

Today we will customize our screenshots.

tl;dr: only read step 7

1 - Base

On linux, almost each distro include a cool soft to make screenshots, e.g. on xfce (xubuntu), I have xfce4-screenshooter.

xfce4-screenshoter

It may sound cool to think "hey can I add some smooth drop shadow to this screenshot ?", and it is indeed a good idea to share good-looking screenshots.

2 - How to do this?

Well, first, let's be sure that nobody ever thought about it.

Uh, someone may have ever thought about the concept of adding cool drop shadow on an image on linux using the command line.
uh oh someone have though of that
Uh. Maybe someone have already thought about that.

Let's see what Takkat said:

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
Enter fullscreen mode Exit fullscreen mode

3 - How do Takkat would do this ?

He uses the command above, with convert, then using +clone -background black and -shadow percent-opacity{xsigma}{+-}x{+-}y{%} and a +swap -background none -layers merge +repage. Is it clear ?

Fortunately, we don't have to fully understand what all this text says, because ImageMagick will understand this correctly and will output a cool looking shadow behind our src image.

4 - Asking the real question

How to add the previous command to a very simple workflow (screenshot page, add it to clipboard -> add shadow to image in clipboard) ?

I already have my screenshot inside my clipboard at the end of the screenshot page, add it to clipboard phase. That's nice.

All I have to do is:
1) Save my screenshot into a file
2) Use the convert command
3) Save the result in a file
4) Copy the file content inside my clipboard
5) Remove the saved file to only keep my clipboard content

And it's pretty easy.

5 - My script

I wrote this script, which essentially does every step and is working flawlessly:

addshadows.sh

#!/bin/bash
xclip -selection clipboard -t image/png -o > "screenshot.png"
convert screenshot.png \( +clone -background black -shadow 75x10+0+0 \) +swap -bordercolor none -border 10 -background none -layers merge +repage shadow.png
xclip -selection clipboard -t image/png -i shadow.png
rm screenshot.png shadow.png
Enter fullscreen mode Exit fullscreen mode

Explanations

  • The first line gets the image stored in my clipboard using xclip, and save it in a file named screenshot.png.
  • Second line is the convert command from imagemagick we've discovered previously. Oh, it also saves the generated image in a file named shadow.png.
  • The third line uses xclip to copy the content of shadow.png into my clipboard.
  • The last line removes the two images from the disk, letting only the shadow version living in my clipboard.

6 - How to launch it?

I already put the xfce4-screenshoter shortcut in my topbar, and that's what I did for my script too!

config for addshadows.sh

XFCE docs have a very good article about launchers, so I think I will let you discover this if you want to.

I added a nice icon in order to recognize it on my topbar:

icons topbar

So now our workflow is :
1) click the (xfce4-)screenshot button button-screenshot

  • click to select type of screenshot (whole screen, current window, part of the screen)
  • select the window/the region
  • click the "copy to clipboard" button

2) click the addshadows.sh button button-screenshot
3) paste our image somewhere on the web and share it


7 - But what if we want to launch it using a keyboard shortcut only ?

This example is gonna use flameshot, a great screenshot tool.

We need to update our script, and to add a new keyboard shortcut.

addshadows_flameshot.sh

#!/bin/bash

flameshot gui -r >> /path/to/addshadows/screenshot.png
convert screenshot.png \( +clone -background black -shadow 75x10+0+0 \) +swap -bordercolor none -border 10 -background none -layers merge +repage shadow.png
xclip -selection clipboard -t image/png -i shadow.png
rm screenshot.png shadow.png
Enter fullscreen mode Exit fullscreen mode

As you can see in the source code, we just replaced the line where we save an image from our clipboard by the flameshot command (that will then save a screenshot.png file), and we added full paths of files (the script will be launched from ~, so it will need to know where to find/save the images).

Here's the command that you need to bind to a keyboard event:

/path/to/addshadows/addshadows_flameshot.sh
Enter fullscreen mode Exit fullscreen mode

Fortunately, it's very easy to add a new shortcut using xfce (and any other linux distro).

shortcut added

You now just have to push a key to enter the screenshot-mode of flameshot, and then a shadow will automatically be added to your image!


8 - An example?

All the screenshots on this page are using this trick, but here it is:

source code of the program

Edit: made a slow-mo on this short video to show the creation of the files (and their deletion) :)


Thank you for reading this article!

Have fun with screenshots using a powerful tool and adding pretty shadows :)

Top comments (0)