Skip to content

Instantly share code, notes, and snippets.

@scmanjarrez
Created July 24, 2025 19:31
Show Gist options
  • Save scmanjarrez/845601bec023760dd93c399e08fb296e to your computer and use it in GitHub Desktop.
Save scmanjarrez/845601bec023760dd93c399e08fb296e to your computer and use it in GitHub Desktop.
Channel swap plugin for gimp 3.x (Convert ZBP texture to be compatible with Blender)
#!/usr/bin/env python3
# Store this file in blender plug-ins directory, e.g. /xxx/GIMP/3.0/plug-ins/channel_swap
import sys
import gi
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
gi.require_version('GimpUi', '3.0')
from gi.repository import GimpUi
from gi.repository import GLib
from gi.repository import Gio
from pathlib import Path
class VdmChannelMixer(Gimp.PlugIn):
def do_query_procedures(self):
return ['blender-vdm-channel-mixer']
def do_create_procedure(self, name):
procedure = Gimp.ImageProcedure.new(self, name, Gimp.PDBProcType.PLUGIN, self.run, None)
procedure.set_image_types("RGB*")
procedure.set_menu_label("Channel swap (VDM compatible with Blender)")
procedure.set_documentation("Swap green and blue channels. Green -> Blue 2.0; Blue -> Green 2.0.", "Swap green and blue channels so it's compatible with Blender VDM textures.", "")
procedure.set_attribution("scmanjarrez", "scmanjarrez", "2025")
procedure.add_menu_path('<Image>/Filters/BlenderVDM/')
return procedure
def run(self, procedure, run_mode, image, drawables, config, run_data):
for img in Gimp.get_images():
# Backup original file
path = Path(img.get_file().get_path())
orig_file = Gio.File.new_for_path(str(path.with_stem(f"{path.stem}_original")))
img.get_file().copy(orig_file, Gio.FileCopyFlags(0), None, None, None)
# Swap channels
layer = img.get_layers()[0]
gaussian_filter = Gimp.DrawableFilter.new(layer, "gegl:channel-mixer", "")
gaussian_filter_config = gaussian_filter.get_config()
gaussian_filter_config.set_property('bg-gain', 2.0)
gaussian_filter_config.set_property('gg-gain', 0.0)
gaussian_filter_config.set_property('bg-gain', 2.0)
gaussian_filter_config.set_property('bb-gain', 0.0)
gaussian_filter.update()
layer.merge_filter(gaussian_filter)
# Save the file
Gimp.file_save(Gimp.RunMode(1), img, img.get_file(), None)
return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
Gimp.main(VdmChannelMixer.__gtype__, sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment