Does anyone know how I can copy a grayscale image into the alpha channel of another image? This is important because some game engines attribute special meaning to the alpha channel of images that would normally involve a totally separate image. (I suppose it’s a memory saving feature.) For example, the specular map might be placed in the alpha channel of the diffuse texture.
Since this is a Blender Python forum I guess you want to write a script for it? That would be of interest to me as well for similar reasons to yours.
Currently, I use external image editors or tools to achieve that purpose. It hadn’t occurred to me to use some internal Blender process as I usually edit the image externally and use it as a UV mapped texture.
I believe the image layer project adds abilities to switch channels:
And I added swizzle support to an own custom build. But no transfer between different images.
You can do this with a script however:
import bpy source = bpy.data.images['Source'] target = bpy.data.images['Target'] source_pixels = source.pixels[:] target_pixels = list(target.pixels) assert len(source_pixels) == len(target_pixels) for i in range(0, len(source_pixels), 4): target_pixels[i+3] = source_pixels[i] target.pixels[:] = target_pixels target.update()
Two images of the same pixel count are expected (and actually also same width and height, otherwise results will be odd).
One needs to be called Source, the other Target. The red channel values are copied to the target’s alpha channel (in a grayscale image, red, green and blue channels should be identical).