user iconVector Lightning on October 20th 2014
3364 views

topic icontopic iconRequest: Black&White to Black & Transparent?

Can you make a script that makes white invisible, grey transparent, and so on?

I'm looking for a script to make a transparent image from a black-and-white one, that does so by erasing all the white, and replacing the greys with transparent black. This may be possible in other ways that I haven't figured out yet... Is this a scripting problem or is another method better?

user iconVlasta on October 20th 2014 0

yes, script is probably the best way

var image = Document.RasterImage;
var sizeX = image.sizeX;
var sizeY = image.sizeY;
var tmp = Blender.CreateCanvas(sizeX, sizeY, 0);
Blender.Compose(tmp, 0, 0, sizeX, sizeY, image, 0, 0, 0, Blender.OpMapChannels,
    Blender.MapChannels(Blender.ChR, Blender.ChG, Blender.ChB, Blender.ChA,
                        Blender.ChEmpty, Blender.ChEmpty, Blender.ChEmpty, Blender.ChR));
Blender.Compose(tmp, 0, 0, sizeX, sizeY, null, 0, 0, 0xff000000, Blender.OpXor);
Blender.Compose(image, 0, 0, sizeX, sizeY, tmp, 0, 0, 0, Blender.OpSrc);
user iconVector Lightning on October 22nd 2014 0

Perfect! Thank you so much!

You know, maybe a plugin that lets the user (or makes it obvious how to) save scripts would be useful. I've used most of these scripts once or twice...

user iconVlasta on October 22nd 2014 0

Adding new functions in a user-friendly manner would be good, but it needs to be well designed. I'll see what can be done.

user icon