It is currently Mon Jul 22, 2024 6:27 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Layers-to-image-size (by Ofnuts)
PostPosted: Thu Mar 22, 2018 12:12 pm  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
Only informative about a great plugin by Ofnuts

Really a very useful (For those who are looking for this solution for a group of layers (and omissions according to the selection of the text group).
https://www.gimp-forum.net/Thread-ofn-layers-to-image-size.

It should be a permanent addition :yes


Attachments:
Ofn=LaToImSize.png
Ofn=LaToImSize.png [ 357.41 KiB | Viewed 3155 times ]

_________________
Image

Slava
Ukraini!
Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Thu Mar 22, 2018 12:22 pm  (#2) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 13080
Location: Native to NYC living in Arizona, Gimp 2.8 & 2.10, Win 11 PC.
MareroQ wrote:
Only informative about a great plugin by Ofnuts

Really a very useful (For those who are looking for this solution for a group of layers (and omissions according to the selection of the text group).
https://www.gimp-forum.net/Thread-ofn-layers-to-image-size.

It should be a permanent addition :yes

Yes MareroQ,
I agree.
Thanks Ofnuts.

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Thu Mar 22, 2018 1:06 pm  (#3) 
Offline
GimpChat Member

Joined: May 12, 2015
Posts: 4694
Thank you, MareroQ for the information about the script.


Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Thu Mar 22, 2018 2:04 pm  (#4) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12535
Doesn't GIMP already have all layers to image size built in? I have this option. :)


Attachments:
Untitled.png
Untitled.png [ 329.73 KiB | Viewed 3128 times ]

_________________
Lyle

Psalm 109:8

Image
Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Thu Mar 22, 2018 2:08 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
lylejk wrote:
Doesn't GIMP already have all layers to image size built in? I have this option. :)

Not a standard one... And AFAIK these old scripts don't handle layer groups.

_________________
Image


Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Thu Mar 22, 2018 2:14 pm  (#6) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2446
lylejk wrote:
Doesn't GIMP already have all layers to image size built in? I have this option. :)


As Ofnuts reply +

It is an external script, that one I think the fence-post all-layer-to-image-size.scm There is another AllLayersFitToImageSize.scm

Both of those are quite old, do not work on layer groups and flatten the layer, losing transparency.

_________________
Image


Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Thu Mar 22, 2018 6:39 pm  (#7) 
Offline
GimpChat Member
User avatar

Joined: Apr 15, 2017
Posts: 1826
This is a great idea, I could've used this script a few times in the past. Well now I have it for the next time.


Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Fri Mar 23, 2018 12:42 am  (#8) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
Question for Ofnuts:

I do not understand coding into a group of layers.
You are the perfect solution - and I need help

Can you change (or suggest) the code change for the Run Code plugin (by TIN):

https://www.gimplearn.net/viewtopic.php/GIMP-Python-Fu-Scripts/Run-Code-on-Visible-Layers-Script-for-GIMP?f=3&t=1027

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Fri Mar 23, 2018 5:19 am  (#9) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
MareroQ wrote:
Question for Ofnuts:

I do not understand coding into a group of layers.
You are the perfect solution - and I need help

Can you change (or suggest) the code change for the Run Code plugin (by TIN):

https://www.gimplearn.net/viewtopic.php/GIMP-Python-Fu-Scripts/Run-Code-on-Visible-Layers-Script-for-GIMP?f=3&t=1027


As its name implies recursiveResizeLayers() is just a simple recursive function which is called o, an object that has a "layers" attribute (Image or LayerGroup): it iterates the list, and for each item:

* if it's a layer it processes it
* if it's a group, it calls itself recursively

When only visible things are processed, the code won't even call itself on a group which isn't visible because if the group isn't visible, nothing below it will be.

All your script needs is a small adaptation of the routine that creates the list of eligible layers.

_________________
Image


Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Fri Mar 23, 2018 7:56 am  (#10) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
Thank You very much - it's easy for You - for me NO (too few examples to follow). :geek
Your cost-effective coding requires additional learning.
Can You give a specific solution?

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Fri Mar 23, 2018 8:47 am  (#11) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
def recursiveSelectLayers(selectedLayers,parent,all):
    for pos,layerOrGroup in enumerate(parent.layers):
        if all or layerOrGroup.visible:
            if isinstance(layerOrGroup,gimp.GroupLayer):
                recursiveSelectLayers(selectedLayers,layerOrGroup,all):
            else:
               # Add you own criteria here (linked, etc...)
                selectedLayer.append(layerOrGroup)

apply_layers = []
recursiveSelectLayers(apply_layer,image,all)


A question I cannot answer for you is whether a layer in a linked group is considered linked or not.
The code below assume we don't care about groups

An efficient way to handle this is to have an array of test functions and to pass the function as a parameter:

# instead of having a cascade of if's, let's define simple yay/nay test functions
# https://www.youtube.com/watch?v=z43bmaMwagI

def testAll(layerOrGroup):
    return True;

def testVisible(layerOrGroup):
    return layerOrGroup.visible

# we assume the grous are always linked if the test only pertains to the layer
def testLinked(layerOrGroup):
    return true if isinstance(layerOrGroup,gimp.GroupLayer) else layerOrGroup.linked

def testNotLinked(layerOrGroup):
    return true if isinstance(layerOrGroup,gimp.GroupLayer) else not layerOrGroup.linked

# The list of yay/nay functions. Note that we never deal explicitly with the index
# Functions and labels are implicitly linked here, the array can be reordered without
# having to change the code elsewhere
# First item is the name as show in the dialog, second item is the function to use
testFunctions=[('All',testAll),('Visible',testVisible),('Linked',testLinked),('Not linked',testNotLinked)]

def recursiveSelectLayers(selectedLayers,parent,testFunction):
    for pos,layerOrGroup in enumerate(parent.layers):
        if testFunction(layerOrGroup):
            if isinstance(layerOrGroup,gimp.GroupLayer):
                recursiveSelectLayers(selectedLayers,layerOrGroup,testFunction):
            else:
                selectedLayer.append(layerOrGroup)

def python_run_code_on_visible_layers(image, layer, test, code):
    # 'test' is really an index over testFunctions, so e can get the function member of the tuples
    testFunction=testFunctions[test][1]
    apply_layers = []
    recursiveSelectLayers(apply_layers,image,testFunction):

# and in the registration, we use the first item of the tuples as the function label.
    (PF_OPTION, "test","Choose on what layers", 1, [tf[0] for tf in testFunctions]),


Warning: untested, syntax errors can happen, this doesn't invalidate the design.

_________________
Image


Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Fri Mar 23, 2018 9:05 am  (#12) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12535
Ah; must have been a carry over of something I downloaded a long time ago. lol

Cool that you added layer group support, ofnuts. :)

_________________
Lyle

Psalm 109:8

Image


Top
 Post subject: Re: Layers-to-image-size (by Ofnuts)
PostPosted: Sat Mar 24, 2018 12:00 am  (#13) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
Hi Mr Ofnuts

Thank You very much for Your help in trying to understand the code for groups of layers - now is the time to implement information for specific solutions - let the road be too long :geek

_________________
Image

Slava
Ukraini!


Top
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Image quality and file size hacks

9

No new posts Attachment(s) Someone Please Help Me Understand Why Is the Gimp Image Size Bigger

4

No new posts Attachment(s) ( solved) dimensions of the image on several linked layers

4

No new posts Attachment(s) Made An Animated GIF With An Ofnuts Script

35

No new posts Attachment(s) Outline Layer Contents by Ofnuts

2



* Login  



Powered by phpBB3 © phpBB Group