[ Prev | Index | Next ]
Japanese English
Now Loading...
Download
Please download on PC (not smartphone) and extract the ZIP file. Then double-click VCSSL.bat (batch file) to execute for Microsoft® Windows®, or execute VCSSL.jar (JAR file) on the command line for Linux® and other OSes.
For details, see How to Use.
You are free to use and modify this program and material, even for educational or commercial use. » Details

A Simple Tool for Making Specific Colors Transparent

This program is a lightweight VCSSL-based tool that opens an image file, replaces a specific color with transparency, and saves the result.

» Looking for the batch processing version? Click here!

If you're making your own game or website, you've probably run into situations where you want to make the background of an image transparent.

Most graphic editing software supports this kind of operation, but if you frequently do simple conversions like "make green transparent," it can be a hassle to open the software, go through menus, apply transparency, and save the file each time. That's why this program was created as a simple tool focused on that one task.

- Table of Contents -

Sponsored Link


How to Use

Download and Extract

At first, click the "Download" button at the above of the title of this page by your PC (not smartphone). A ZIP file will be downloaded.

If you are using Windows, right-click the ZIP file and choose "Properties" from the menu, and enable "Unblock" checkbox at the right-bottom (in the line of "Security") of the properties-window. Otherwise, when you extract the ZIP file or when you execute the software, security warning messages may pop up and the extraction/execution may fail.

Then, please extract the ZIP file. On general environment (Windows®, major Linux distributions, etc.), you can extract the ZIP file by selecting "Extract All" and so on from right-clicking menu.

» If the extraction of the downloaded ZIP file is stopped with security warning messages...

Execute this Program

Next, open the extracted folder and execute this VCSSL program.

For Windows

Double-click the following batch file to execute:

VCSSL__Double_Click_This_to_Execute.bat

For Linux, etc.

Execute "VCSSL.jar" on the command-line terminal as follows:

cd <extracted_folder>
java -jar VCSSL.jar

» If the error message about non-availability of "java" command is output...

If You Run Out of Memory While Running the Program...

Depending on how you use it, this program may consume a considerable amount of memory. As a result, the default memory allocation may not be sufficient in some cases. If you encounter such issues, please refer to the following:

» When You Run Out of Memory While Running the Program (for Microsoft® Windows® Users)
» When You Run Out of Memory While Running the Program (for Linux® and Other OS Users

Note: As a rough estimate, when processing a photo with a resolution of 4288 x 2848 pixels (about 12 megapixels), allocating around 3 GB (≈ 3000 MB) of memory should be sufficient for the program to run.

Selecting a File

When you launch the program, a file selection window will appear. Choose the image file you want to process and make part of it transparent.

As a sample, there's a file named sample.png included in the folder you downloaded and extracted. Try selecting that one first. It's a simple image of a person drawn over a green background.

Sample Image
Sample Image "sample.png"
Included in the folder you downloaded and extracted.

Note: This tool only makes colors that exactly match the specified color transparent. It is not suitable for JPEG images, because JPEG's lossy compression causes color variation ("noise") that prevents an exact match.

Use PNG or BMP files instead, and make sure the color you want to make transparent is uniformly filled.

Specifying the Color to Make Transparent

After selecting the file, you'll be prompted to input the color to make transparent. Instead of entering a color name, you'll be asked to input the red, green, and blue (RGB) values, each from 0 to 255.

If you're not familiar with RGB values, check out the page below. It includes an explanation and a handy color display tool:

For example, to make the green in the sample image transparent, you would enter: Red = 0, Green = 255, Blue = 0.

Saving the Transparent Image (Automatic)

Once you've entered the target color, the tool will automatically save a new version of the image with that color made transparent.

The new file's name will be the same as the original, but with "_clear.png" appended to the end. The output format will be PNG.

Here's the result of running the tool on the sample image. As you can see, the green background has been made transparent, and the gray behind it is now visible.

Result of making the sample image transparent
Result of making the sample image transparent: "sample.png_clear.png"
The green parts of the original image have been made transparent.

A Batch Version for Multiple Files Is Also Available!

If you have a lot of images to process, repeating the steps above for each file can get tedious. In that case, try the batch version of this tool, which processes all PNG images in a folder and saves the results to another folder:

Simple Tool for Making Specific Colors Transparent (Batch Version)
This version loads all PNG images in a folder, replaces the specified color with transparency, and saves the results to a separate folder.

Code Overview

This program is written in VCSSL.

If you want to replace the color with something other than transparency, you can modify the source code in the file ColorToClear.vcssl using any text editor.

Since VCSSL is a scripting language, no separate compiler is needed-just edit and run. Its syntax is C-like and very simple, so if you're familiar with C or similar languages, you should find it easy to understand.

Full Code

Let's take a look at the full source code:

That's it! Just under 40 lines of code. Each part is briefly explained in the comments, but in the next section we'll go through it in a bit more detail.

Header Section

Let's start with the first two lines of the code:

The first line declares that the file is encoded in UTF-8. While the program will usually work fine without this line, including it helps prevent character corruption (garbled text).

The second line imports the Graphics library, which provides functions for handling graphics data -- in other words, image data. In VCSSL, image files are opened, displayed, or drawn by loading them into a data structure called a "graphics resource."

Selecting a File and Creating a Graphics Resource

Next is the part where we open the image file:

The choose(...) function prompts the user to select a file and returns the selected file's path as a string. We store this path in the variable "inputFilePath".

Then we pass that file path to the newGraphics(...) function, which opens the image file and loads it into memory as a graphics resource. This is how the image is made available for processing.

The newGraphics(..) function returns an ID number assigned to the newly created graphics resource, which we store in the integer variable "inputGraphics".

This ID allows us to distinguish between different graphics resources -- especially important later, when we create the modified image.

Defining the Replacement Color (Transparent)

Here's the section where we define the replacement color -- i.e., the color that will replace the specified one:

These variables define the red, green, blue, and alpha values of the new color. If you want to replace the specified color with something other than transparency, modify these values as needed.

By default, "toAlpha" is set to 0 to make the result fully transparent (0 means completely transparent, 255 means completely opaque).

For example, if you change "toGreen", "toBlue", and "toAlpha" to 255 and run the program:

Result After Modification
Result After Modification
The green background is replaced with cyan (instead of being made transparent).

As shown, the green parts are replaced with cyan instead of being made transparent. (In RGB, cyan is made by combining full green and full blue.)

Creating the Modified Graphics Resource

Now we get to the core operation: replacing the color in the image. It's handled by simply calling newGraphics(...) again, this time with more arguments:

When called with these arguments, newGraphics(...) creates a new graphics resource by copying the original one and replacing the specified color (fromRed, ..., fromAlpha) with the new color (toRed, ..., toAlpha).

The resulting resource is assigned an ID number, which we store in "outputGraphics". We'll use this later when saving the file.

Saving the File

Now for another important step: saving the result to a file:

We create a new filename by appending "_clear.png" to the original. This avoids overwriting the original file.

Then we call "exportGraphics" to save the modified image as a PNG file, and use "popup" to show a completion message including the saved file path.

Finishing Up

Finally, we clean up the graphics resources and exit the program:

deleteGraphics(...) releases the graphics resources from memory. Although these would be released automatically when the program exits, we do it explicitly here as a good practice.

Then we call exit() to end the program. (Without this line, the console would remain open until manually closed.)

That's all for the code!

License

This VCSSL/Vnano code (files with the ".vcssl" or ".vnano" extensions) is released under the CC0 license, effectively placing it in the public domain. If any sample code in C, C++, or Java is included in this article, it is also released under the same terms. You are free to use, modify, or repurpose it as you wish.

* The distribution folder also includes the VCSSL runtime environment, so you can run the program immediately after downloading. The license for the runtime is included in the gLicenseh folder.
(In short, it can be used freely for both commercial and non-commercial purposes, but the developers take no responsibility for any consequences arising from its use.) For details on the files and licenses included in the distribution folder, please refer to "ReadMe.txt".

* The Vnano runtime environment is also available as open-source, so you can embed it in other software if needed. For more information, see here.



Sponsored Link



Japanese English
[ Prev | Index | Next ]
Simple Tool for Viewing and Converting Between RGB Values and Color Codes

Display and Convert RGB Values and Color Codes on a GUI Tool
A Simple Tool for Making Specific Colors Transparent (Batch Processing Version)

Batch-Convert a Specific Color to Transparency in All PNG Files in a Folder
A Simple Tool for Making Specific Colors Transparent

Convert a Specific Color to Transparency in PNG Image Files
Simple Tool for Animating Sequential Images

A lightweight tool developed with VCSSL that allows you to play back sequential image files as an animation without converting them into a video file.
Vertex Array-Based Model Deformation Animation

How to Deform 3D Surface Models Using a Grid-Based Vertex Array
Creating a Model from a Vertex Array (Quadrangle Grid Mesh Format)

How to Create 3D Surface Models from a Grid-Based Vertex Array
Index
[ Prev | Index | Next ]
Simple Tool for Viewing and Converting Between RGB Values and Color Codes

Display and Convert RGB Values and Color Codes on a GUI Tool
A Simple Tool for Making Specific Colors Transparent (Batch Processing Version)

Batch-Convert a Specific Color to Transparency in All PNG Files in a Folder
A Simple Tool for Making Specific Colors Transparent

Convert a Specific Color to Transparency in PNG Image Files
Simple Tool for Animating Sequential Images

A lightweight tool developed with VCSSL that allows you to play back sequential image files as an animation without converting them into a video file.
Vertex Array-Based Model Deformation Animation

How to Deform 3D Surface Models Using a Grid-Based Vertex Array
Creating a Model from a Vertex Array (Quadrangle Grid Mesh Format)

How to Create 3D Surface Models from a Grid-Based Vertex Array
News From RINEARN
* VCSSL is developed by RINEARN.

Released: Latest Version of VCSSL with Fixes for Behavioral Changes on Java 24
2025-04-22 - VCSSL 3.4.50 released with a fix for a subtle behavioral change in absolute path resolution on network drives, introduced in Java 24. Details inside.

Released the Latest Versions of RINEARN Graph and VCSSL - Now Supporting Customizable Tick Positions and Labels!
2024-11-24 - Starting with this update, a new "MANUAL" tick mode is now supported, allowing users to freely specify the positions and labels of ticks on the graph. We'll explain the details and how to use it.

Released Exevalator 2.2: Now Compatible with TypeScript and Usable in Web Browsers
2024-10-22 - The open-source expression evaluation library, Exevalator, has been updated to version 2.2. It now supports TypeScript and can be used for evaluating expressions directly in web browsers. Explains the details.

Behind the Scenes of Creating an Assistant AI (Part 1: Fundamental Knowledge)
2024-10-07 - The first part of a series on how to create an Assistant AI. In this article, we introduce the essential knowledge you need to grasp before building an Assistant AI. What exactly is an LLM-based AI? What is RAG? And more.

Launching an Assistant AI to Support Software Usage!
2024-09-20 - We've launched an Assistant AI that answers questions about how to use RINEARN software and helps with certain tasks. Anyone with a ChatGPT account can use it for free. We'll explain how to use it.

Software Updates: Command Expansion in RINEARN Graph, and English Support in VCSSL
2024-02-05 - We updated our apps. This updates include "Enhancing the Command-Line Features of RINEARN Graph" and "Adding English Support to VCSSL." Dives into each of them!

Inside the Repetitive Execution Speedup Impremented in Vnano Ver.1.1
2024-01-17 - Delves into the update in Vnano 1.1 from a developer's viewpoint, providing detailed insights into the specific improvements made to the internal structure of the script engine.

Scripting Engine Vnano Ver.1.1 Released: Dramatic Speed Improvement for Repetitive Executions of the Same Content
2023-12-22 - Released the Vnano script engine Ver.1.1. In this version, we've made significant enhancements in processing speed by reducing the overhead of handling requests. Explains the details.