Skip to content

Converts any opaque image to one with a transparent background. The background color is automatically detected (i.e. the colour of the 1st pixel in the image will be considered the background color).

padurean/make-image-transparent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Make image transparent

Detects the background color of an opaque image by looking at the color of the 1st pixel, then makes transparent (sets the alpha channel value to 0 for) all the pixels which have the same color as the detected background one (within some tolerance values - see colorTolerance and colorToleranceUniform variables in main.go). Saves the output as PNG.

Supported file types:

jpeg, jpg, png, bmp, tiff, gif and webp.

Build

Implemented in golang. To build an executable for your operating system run go build.

Example:

/make-image-transparent sample--yellow-on-red--jpg.jpg

It also accepts a second (boolean) argument (true | false). Example:

/make-image-transparent sample--grey-on-white--jpg.jpg true

If true is specified => the image data will also be encoded to a Base64 string and decoded back (this is done just as an example on how to that, in case one needs to work with Base64 encoded images). Unfortunately this is not supported for webp images as the used library only supports decoding webp image data from Base64, but it doesn't also support encoding it back to Base64.

About

Converts any opaque image to one with a transparent background. The background color is automatically detected (i.e. the colour of the 1st pixel in the image will be considered the background color).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages