dannye33

batch-spritify.py

Feb 16th, 2022 (edited)
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # ffmpeg -i *.gif -r 6.0 `basename *.gif .gif`%4d.png; gimp-console -i -b '(python-fu-batch-spritify RUN-NONINTERACTIVE "*.png")'
  4.  
  5. import math
  6. from gimpfu import *
  7.  
  8. def batch_spritify(glob="*.png"):
  9.     files = pdb.file_glob(glob, 1)
  10.     for file in files[1]:
  11.         timg = pdb.gimp_file_load(file, file)
  12.         tdrawable = pdb.gimp_image_get_active_drawable(timg)
  13.         pdb.gimp_image_undo_group_start(timg)
  14.         pdb.gimp_desaturate_full(tdrawable, DESATURATE_LIGHTNESS)
  15.         pdb.gimp_image_convert_indexed(timg, NO_DITHER, CUSTOM_PALETTE, 0, FALSE, FALSE, "RGBDS")
  16.         pdb.gimp_image_scale_full(timg, tdrawable.width/2, tdrawable.height/2, INTERPOLATION_NONE)
  17.         pdb.gimp_image_resize(timg, 56, 56, (56-tdrawable.width)/2, (56-tdrawable.height)/2)
  18.         pdb.gimp_image_convert_grayscale(timg)
  19.         pdb.gimp_image_flatten(timg)
  20.         pdb.file_png_save_defaults(timg, pdb.gimp_image_get_active_drawable(timg), pdb.gimp_image_get_filename(timg), pdb.gimp_image_get_filename(timg))
  21.         pdb.gimp_image_undo_group_end(timg)
  22.     pdb.gimp_quit(0)
  23.  
  24. register(
  25.         "batch_spritify",
  26.         "Make the specified layer look like a sprite",
  27.         "Make the specified layer look like a sprite",
  28.         "Danny-E 33",
  29.         "Danny-E 33",
  30.         "2019-2019",
  31.         "<Toolbox>/Python-Fu/_BatchSpritify...",
  32.         "RGB*",
  33.         [
  34.             (PF_STRING, "glob", "glob", "*.png")
  35.         ],
  36.         [],
  37.         batch_spritify)
  38.  
  39. main()
  40.  
Add Comment
Please, Sign In to add comment