How to make super duper shadows for your screenshots
Tags: linux, screenshot, bash, xclip
Published: 2020-08-03 10:15:12

![screenshot](https://up.l3m.in/files/1584131232.png)

Today we will customize our screenshots.

*tl;dr: only read [step 7](#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](https://up.l3m.in/files/1584131412.png)

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](https://duckduckgo.com/?q=add+drop+shadow+cli+linux).

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](https://up.l3m.in/files/1584131595.png)
Uh. *Maybe* someone have already thought about that.

Let's see what [Takkat](https://graphicdesign.stackexchange.com/users/12941/takkat) [said](https://graphicdesign.stackexchange.com/a/117404/144716):

> I would recommend the ultimate command line tool for bitmap manipulations: [ImageMagick](http://www.imagemagick.org/script/index.php).
> 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`](http://www.imagemagick.org/script/command-line-options.php#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:
```bash
convert input.jpg \( +clone -background black -shadow 50x10+15+15 \) +swap -background none -layers merge +repage shadow.png
```

# 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`
```bash
#!/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
```

### 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](https://up.l3m.in/files/1596447356.png)

[XFCE docs](https://docs.xfce.org/xfce/xfce4-panel/launcher) 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](https://up.l3m.in/files/1596449240.png)


So now our workflow is :
1) click the (xfce4-)screenshot button <img src="https://up.l3m.in/files/1596448764.png" alt="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 <img src="https://up.l3m.in/files/1596448786.png" alt="button-screenshot" />
3) paste our image somewhere on the web and share it

----

# <a name="step-7"></a>7 - But what if we want to launch it using a keyboard shortcut only ?

*This example is gonna use [flameshot](https://github.com/lupoDharkael/flameshot), a great screenshot tool.*

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

> `addshadows_flameshot.sh`
```bash
#!/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
```

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:

```bash
/path/to/addshadows/addshadows_flameshot.sh
```

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

![shortcut added](https://up.l3m.in/files/1596448953.png)

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](https://up.l3m.in/files/1584132666.png)

**Edit:** made a slow-mo on [this](https://up.l3m.in//files/1596468852-screenshot-slow.webm) 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 :)