Created
February 3, 2018 23:38
-
-
Save pezcode/c221d6b62338fab0a674a0845d81d111 to your computer and use it in GitHub Desktop.
GIMP plugin script to hue-shift an image several times (e.g. for animations)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from gimpfu import * | |
from gimpenums import * | |
import os | |
def batch_hue_shift(image, drawable, count, outdir): | |
assert 2 <= count <= 360 | |
folder, filename = os.path.split(image.filename) | |
filebase, fileext = os.path.splitext(filename) | |
if not outdir: | |
outdir = folder | |
count = int(count) | |
step = 360.0 / count | |
# gimp_file_save overwrites the progress bar with the file name every time | |
# so setting progress values is essentially pointless | |
for i in range(0, count): | |
# create a temporary copy of the input image | |
# the output image will only have one merged layer! | |
dupimage = pdb.gimp_image_duplicate(image) | |
dupimage.disable_undo() | |
dupimage.merge_visible_layers(CLIP_TO_IMAGE) # flatten() removes alpha | |
dupdrawable = dupimage.active_layer | |
shift = i*step | |
if shift > 180: | |
shift -= 360 | |
pdb.gimp_hue_saturation(dupdrawable, ALL_HUES, shift, 0, 0) | |
newname = filebase + ("_%03d" % (i+1)) + fileext | |
newpath = os.path.join(outdir, newname) | |
pdb.gimp_file_save(dupimage, dupdrawable, newpath, newpath) | |
gimp.delete(dupimage) | |
register( | |
"batch_hue_shift", | |
"Hue-shifts an image several times", | |
"Hue-shifts an image several times", | |
"pezcode", | |
"(c) 2014 pezcode", | |
"2014-09-21", | |
"<Image>/_Xtns/Color/Batch _Hue Shift", | |
"RGB*", | |
[ | |
(PF_SPINNER, "count", "Number of images", 20, (2, 360, 1)), | |
(PF_DIRNAME, "outdir", "Output directory", "") | |
], | |
[], | |
batch_hue_shift | |
) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment