It is currently Sun Jun 30, 2024 5:19 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Shuffle Layers Context (sizes & positions)
PostPosted: Thu Feb 16, 2023 8:44 pm  (#1) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3999
Location: Canada
This was for me to have fun I thought I'd share it.
I had an image with many textured colors on their own layers (cropped to content).
And I wanted to create shuffled context, so that the colored texture would be shuffled but not the line drawing layers (first 2 layers) defaulted to be ignored (which you can specify when you run plug-in and it also assumes that bottommost layer is background layer and will not be part of context shuffle.
Anyways.
You can create something like this with this plug-in if you make 3 different shuffles.

plug-in menu location: Python-Fu/Shuffle Layers Sizing and Positions...

#!/usr/bin/env python
# shuffle-layers-and-sizes.py
# Created by TT
#
# License: GPLv3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release

from gimpfu import *
import random
def python_shuffle_layers_sizes(image, layer, ignore) : #FUNCTION DEFINITION
   pdb.gimp_image_undo_group_start(image)
   pdb.gimp_context_push()
   #YOUR CODE BEGINS=======================
   layers = []
   sizepositions = []
   ignore = int(ignore)
   #Shuffle everything except bottommost layer, assuming it's background
   for i in range(ignore,len(image.layers)-1):
      l = image.layers[i]
      layers.append(l)
      offset_x,offset_y = pdb.gimp_drawable_offsets(l)
      sizepositions.append([offset_x,offset_y,l.width,l.height])
   random.shuffle(sizepositions)
   new_image = pdb.gimp_image_new(image.width,image.height,RGB)
   pdb.gimp_display_new(new_image)
   
   #insert the background first
   layer_copy = pdb.gimp_layer_new_from_drawable(image.layers[len(image.layers)-1],new_image)
   pdb.gimp_image_insert_layer(new_image,layer_copy,None,0)

   #then insert the shuffled layers
   for i in range(len(layers)-1,-1,-1):
      layer_copy = pdb.gimp_layer_new_from_drawable(layers[i],new_image)
      pdb.gimp_image_insert_layer(new_image,layer_copy,None,0)
      pdb.gimp_item_transform_scale(layer_copy,sizepositions[i][0],sizepositions[i][1],sizepositions[i][0]+sizepositions[i][2],sizepositions[i][1]+sizepositions[i][3])

   for i in range(ignore-1,-1,-1):
      layer_copy = pdb.gimp_layer_new_from_drawable(image.layers[i],new_image)
      pdb.gimp_image_insert_layer(new_image,layer_copy,None,0)
   #YOUR CODE ENDS ========================
   pdb.gimp_context_pop()
   pdb.gimp_image_undo_group_end(image)
   pdb.gimp_displays_flush()
    #return

register(
   "python_fu_shuffle_layers_sizes",
   "Shuffles layers sizing and position features",
   "Shuffles layers sizing and position features",
   "TT",
   "TT",
   "Feb 16, 2023",
   "<Image>/Python-Fu/Shuffles Layers Sizing and Position...",
   "*",      # Create a new image, don't work on an existing one
   [
   #INPUT BEGINS
   #(PF_OPTION, "arrow_side", "Arrows Ends:", SIDE_END, SIDE_NAMES),
   #(PF_TOGGLE, "arrow_close", "Arrows Close:", 0),
   (PF_SPINNER, "ignorelayers", "Ignore first (no of layers):", 2, (0, 200, 1)),
   #(PF_SPINNER, "shadow_offset_x", "Shadow Offset X:", 6, (-4096,4096,1)),
   #(PF_SPINNER, "shadow_offset_y", "Shadow Offset Y:", 6, (-4096,4096,1)),
   #(PF_SPINNER, "shadow_blur_radius", "Shadow Blur Radius:", 15, (0,1024,1)),
   #(PF_SPINNER, "shadow_opacity", "Shadow Opacity:", 100, (0,100,1)),
   #INPUT ENDS
   ],
   [],
   python_shuffle_layers_sizes)

main()


Image

_________________
TinT


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts How do I change context menu text color in my theme?

0

No new posts Wacom Tablet, attempting to draw invokes context menu

2

No new posts Layers

2

No new posts Attachment(s) Wrap all layers

4

No new posts Help with masks and layers please!

3



* Login  



Powered by phpBB3 © phpBB Group