Skip to content

Instantly share code, notes, and snippets.

@icanwalkonwater
Last active August 30, 2018 12:45
Show Gist options
  • Save icanwalkonwater/e6787a092ed69314a2c4f17b6f19ccc4 to your computer and use it in GitHub Desktop.
Save icanwalkonwater/e6787a092ed69314a2c4f17b6f19ccc4 to your computer and use it in GitHub Desktop.
A gimp plugin that allows you to create a rotating gif from your selected layer.
#!/usr/bin/env python
from gimpfu import *
import math
def python_gif_rotate(image, base_layer, rotation=360, amount=60, time=1000, clockwise=True,
center_auto=True, center_x=0, center_y=0, auto_resize=True):
step_rot = rotation / amount
if not clockwise:
step_rot = -step_rot
time_per_frame = time / amount
suffix = " (%sms) (replace)" % time_per_frame
for step in range(1, amount):
next_layer = base_layer.copy()
image.add_layer(next_layer, 0)
pdb.gimp_item_transform_rotate(next_layer, math.radians(step_rot * step),
center_auto, center_x, center_y)
next_layer.name += " (step %s)%s" % (step, suffix)
if auto_resize:
pdb.gimp_layer_resize_to_image_size(next_layer)
base_layer.name += suffix
register(
"python_fu_gif_rotate",
"Used to make a gif that rotate by a defined amount of percent step by step.",
"Used to make a gif that rotate by a defined amount of percent step by step.",
"Jesus_Crie",
"Jesus_Crie",
"2018",
"<Image>/Filters/Animation/Rotate Image...",
"*",
[
(PF_INT, "rotation", "Full rotation (degrees)", 360),
(PF_INT, "amount", "Amount of images to generate (some sort of FPS)", 60),
(PF_INT, "time", "Amount of time for the rotation (ms)", 1000),
(PF_BOOL, "clockwise", "Rotate clockwise ?", True),
(PF_BOOL, "center_auto", "Automatically set the center (center of selection)", True),
(PF_INT, "center_x", "Manual center of rotation (x)", 0),
(PF_INT, "center_y", "Manual center of rotation (y)", 0),
(PF_BOOL, "auto_resize", "Automatically resize the created layers to image size", True)
],
[],
python_gif_rotate)
main()
#!/usr/bin/env python
from gimpfu import *
def python_slice_n_save(image, layer, horizontal=2, vertical=2, name='', file='', auto_convert=True):
if not len(name) == 0:
pdb.gimp_image_set_filename(image, name + '.gif')
if not file.endswith('/'):
file += '/'
# Convert to indexed colors
if pdb.gimp_drawable_is_indexed(layer) == 0:
if auto_convert:
pdb.gimp_image_convert_indexed(image, 0, 0, 255, 0, 1, '')
else:
pdb.gimp_message('WARNING: You need to convert your image to indexed colors mode.')
return
# Delete other guides
last_id = pdb.gimp_image_find_next_guide(image, 0)
while not last_id == 0:
pdb.gimp_image_delete_guide(image, last_id)
last_id = pdb.gimp_image_find_next_guide(image, 0)
h_slices = 100 / horizontal
for i in range(1, horizontal):
percent = h_slices * i
pdb.script_fu_guide_new_percent(image, layer, 1, percent)
v_slices = 100 / vertical
for i in range(1, vertical):
percent = v_slices * i
pdb.script_fu_guide_new_percent(image, layer, 0, percent)
count, ids = pdb.plug_in_guillotine(image, layer)
output_images = [img for img in gimp.image_list() if img.ID in ids]
for image in output_images:
print(file + image.name)
pdb.file_gif_save(image, layer, file + image.name, file + image.name,
0, 1, 100, 2)
for image in output_images:
pdb.gimp_image_delete(image)
register(
'python_fu_slice_and_save',
'Used to slice the image in a number of pieces and export them.',
'Used to slice the image in a number of pieces and export them.',
'Jesus_Crie',
'Jesus_Crie',
'2018',
'<Image>/Image/Transform/Slice \'n save...',
'*',
[
(PF_INT, 'horizontal', 'Horizontal slices', 2),
(PF_INT, 'vertical', 'Vertical slices', 2),
(PF_STRING, 'name', 'Basename of the exported files', ''),
(PF_DIRNAME, 'file', 'Output directory', ''),
(PF_BOOL, 'auto_convert', 'Automatically convert image to indexed colors mode (if necessary)', True)
],
[],
python_slice_n_save
)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment