Monday, May 17, 2010: Abscapture - Take Screenshot with Transparency (for Linux) « from the old blog archive »
It has once been posted on my old blog, since my old blog is gone forever, I'm going to re-post this tool.
Abscapture is a tool written in Python that allows you to take screenshots with alpha transparency.
This tools work by capturing 2 screenshots. The first screenshot is the object on black background. The second screenshot is the same object on white background. The application then merges these 2 images together using a simple algorithm, producing a alpha-blended version of it.
Here is an overview of an algorithm.
- Finding the alpha component. Because in each pixel, the red, green and blue components shares the same opacity (which is the alpha component), here is a way to find the alpha channel.
- Let B is the average of red, green and blue components of each pixel on the black image.
- Let W is the average of red, green and blue components of the same pixel on the white image.
- The transparency of that pixel in the resulting image is simply W - B. Imagine these examples.
- If the pixel is opaque, then B will be equal to W. The transparency is 0%.
- If the pixel is transparent, then B will be 0% and W will be 100%. The transparency is 100%.
- The alpha/channel opacity is the 100% - transparency or 100% - W + B.
- Finding the color component.
- Let Vb be the value of a component (red, green, or blue) of a pixel on the black image.
- Let Vw be the value of that component of that pixel on the white image.
- Let Vr be the value of that component of that pixel on the resulting image.
- Let A be the opacity of that pixel (calculated using above formula).
- You can see that:
- Vb will go towards 0% when opacity decreases, while Vw will go towards 100% when opacity increases.
- We can find Vr by solving two simultaneous equation:
- Vr * A = Vb
- Vr * A = 100% - Vw
- That means: Vr = Vb / A.
- There is a case where the pixel is transparent, A = 0. There is a need to check for it too or it's division by zero.
Now, let's see how the resulting image looks like:
Download it! abscapture-2010-05-17.tar.gz
How to use abscapture?
First, install scrot.
After you extract the files, double click on abscapture.py and click "run."
A dialog box will open, telling you to set up the scene.
Minimize all windows that you don't want in your screenshot. Leaving only the desktop, the panel and the windows you want. When you're ready, press OK. You will have 5 seconds to open up menus, tooltips, or additional elements you want in your screenshot.
After 5 seconds, the desktop changes to white. About 3 seconds later, the desktop changes to back. 3 seconds and then the desktop returns to normal. A window with a progress bar will appear. Wait for it to finish. That window with progress bar closes automatically when finish. You will have the file result.png which is your screenshot!
And again, I hope that someone will pick this up and improve this tool or incorporate the feature of this tool into other software.
Please add a comment if you have done so, or if you just want to say thanks, that's OK too!