It is currently Sun Jul 21, 2024 12:32 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 18 posts ] 
Author Message
 Post subject: Export layers as img with group handling
PostPosted: Mon Nov 26, 2012 3:25 am  (#1) 
Offline
GimpChat Member

Joined: Nov 26, 2012
Posts: 10
Hello Gimpchat, it's my first topic here!

I have a .xcf file with 140 layers in several groups. I want to export all this layers in images -> 140 png images.

I found a script working great exept for layers in a group (the script export 1 image by group).

I open the script but it's chineese for me. I just now some php and this script looks very different.

Can you give me some tips to change the script in order to handle groups ans subgroups?

Thanks


Attachments:
File comment: Script save-layers
save-layers-as-img.scm [1.06 KiB]
Downloaded 137 times
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: Export layers as img with group handling
PostPosted: Mon Nov 26, 2012 4:07 am  (#2) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
I haven't heard of a script or plugin that can export layer groups as separate images. Layers in a group have a few limitations compared to normal layers, they're really only for organization and applying a mode or opacity to multiple layers.

Here's another export layers as separate images script to try. It doesn't do grouped layers separately either, so your still stuck. Maybe someone else will chime in with more info for you.
http://registry.gimp.org/node/25394

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Mon Nov 26, 2012 4:51 am  (#3) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2445
That is ancient, 2003

Same as the previous suggestion
This one works http://registry.gimp.org/node/25394 with a caveat.
But, it might still save some time.

In simple terms this works
....layer_group_1
....layer_group_2
ordinary_layer
background

This does not work
....layer_group_1
ordinary_layer
....layer_group_2
background

When it does work all the layers are saved as individual images in order. When it does not work, that pesky intermediate layer is repeated several times replacing what should be the following layers.

It would be nice if this script was fixed.

_________________
Image


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Mon Nov 26, 2012 4:55 am  (#4) 
Offline
GimpChat Member

Joined: Nov 26, 2012
Posts: 10
Thanks Odinbc for your answer.

The script export the same way as my own. When I looked at the script I see for-each statement and I'm wondering if it is possible to detect that a layer is in fact a group and how to loop inside this group.

Do you think this is not possible with scm script? Or do you think that this script doesn't exist yet?


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Mon Nov 26, 2012 5:03 am  (#5) 
Offline
GimpChat Member

Joined: Nov 26, 2012
Posts: 10
Hello rich2005

I try to understand your method so I suppress some layers and folded groups to just have simple configuration:

- Group1
- Layer 1.1
- Layer 1.2
- Layer 1.3
- Group2
- Layer 2.1
- Layer 2.2
- Layer 2.3
- Group3
- Layer 3.1
- Layer 3.2
- Layer 3.3

But the script export 3 png and not 9 as i wish. My only way is to move all my layers at the "root" of the image but I can't select multiple layers to move them.
I have to do this for each 140 layers and I loose my groups whichr are very usefull for me beacause of my number of layers.

I know group is recent in Gimp but i hoppe we can handle group in script.


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Mon Nov 26, 2012 5:09 am  (#6) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
pitibalrog wrote:
Thanks Odinbc for your answer.

The script export the same way as my own. When I looked at the script I see for-each statement and I'm wondering if it is possible to detect that a layer is in fact a group and how to loop inside this group.

Do you think this is not possible with scm script? Or do you think that this script doesn't exist yet?


The Procedure browser is your friend here:
gimp-item-is-group
Returns whether the item is a group item

And related is
gimp-item-get-parent
Returns the item's parent item

gimp-item-get-children
Returns the item's list of children


Kevin


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Mon Nov 26, 2012 5:15 am  (#7) 
Offline
GimpChat Member

Joined: Nov 26, 2012
Posts: 10
Thank you paynekj,

I think It's a good start to update this script. I'll see what I can do, but my scm knowledge is null :)

Where can I have the reference documentation for all this scm scripting?


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Mon Nov 26, 2012 5:22 am  (#8) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
We have a good list of scripting resources right here on GimpChat: viewtopic.php?f=9&t=724

It's very possible that Ofnuts and/or Saulgoode will be along later to say they have already written a suitable script ;)

Kevin


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Mon Nov 26, 2012 5:26 am  (#9) 
Offline
GimpChat Member

Joined: Nov 26, 2012
Posts: 10
Thanks for the link, there's a lot of ressources

I'm started trying to understand scheme with car, cdr, cadr...

But if Ofnuts or Saulgoode can help later I'll wait :-)

I've to do recursive function to handle this and I don't think this is the simplier way to start with a new language ;-)


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Mon Nov 26, 2012 7:55 pm  (#10) 
Offline
GimpChat Member

Joined: Nov 26, 2012
Posts: 10
I finaly make my first script. Thank for your help, learning scheme is not natural for me ressources helps me.

My script work and can handle multiple level with recursive function. I'm happy with it :-)

But now I want to add an other parameter to export only visible layers and I have some trouble with "illegal function" error...

http://stackoverflow.com/questions/1357 ... tion-error

I'm sure it's a simple error but I'm to new with scheme to see it!


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Mon Nov 26, 2012 9:08 pm  (#11) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
(let*
    (
        (nblayers (car listlayers))
        (layers (cadr listlayers))
        (display "EXPORT LAYERS: LAYERS = ")(display layers)(newline)

        (display " onlyvisible: ")(display onlyvisible)(newline) ; <--- HERE IT WORKS
        (index 0)

        (basename (unbreakupstr (butlast (strbreakup filename ".")) "."))
        (extension (car (last (strbreakup filename "."))))
        (layer)
    )

I note two separate problems with your code. One is that you are attempting to execute the display procedure within your let* bindings block. Rather than executing display, it is actually being reassigned with a new value. Since you appear to be using this mainly for debugging purposes, I would propose as a solution that you remove those lines (or at least move them outside of the bindings).

The other problem is also within the same binding block, wherein you evaluate (cadr listlayers). When you get to the point where you are processing the last layer and listlayers is a list containing only one element, then the cdr of that list is empty and has no car. You need to test for this condition.

Here is some code I whipped up which saves the layers to PNG files, though it seems that you are making good progress and should probably just continue with what you're doing. (For what it's worth, the majority of my code is to keep track of the image structure for later reconstruction; I was thinking along the lines of being able to export images back to version 2.6.)

http://chiselapp.com/user/saulgoode/rep ... 58d2e9a1f3

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Tue Nov 27, 2012 3:13 am  (#12) 
Offline
GimpChat Member

Joined: Nov 26, 2012
Posts: 10
Thank saulgoode for your answer.

It finaly works with display outside the binding block. I doesn't understand very well what I was doing, but now it's more clear :)

For the seconde problem, I'll see your code. But I don't have error and all my layers was exported.

I don't have a real recursive function but a function A who call function B who call (if needed) function A.

First my (layers (cadr listlayers)) is only called on with listlayers =
(gimp-image-get-layers imgcopy)
or
(gimp-item-get-children layer)

And this two function returns something like (3 #(55, 32, 25)). If I have only one layer it returns (1 #(55)) and (0 #()) for empty group.
So I think I have to do cadr everytime to get the real list and not the count.

Second, I do a (while (< index nblayers) ... and if nblayers = 0 I dont execute export code.

Can you say me if I'm wrong with this explanation, I'm realy new to this and try to understand this new language.

Thanks again :-)


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Tue Nov 27, 2012 4:22 am  (#13) 
Offline
GimpChat Member

Joined: Nov 26, 2012
Posts: 10
I look at your code. There's so many new things for me ... Yummy :-)

You make me discover parasites, vectors (I already used without knowing), gimp-progress-end

You also make me discover http://chiselapp.com where I can explore more code.

Some more questions I have about your code:
1) Where can I find the complete list of possible parasites like "gimp-comment"?
2) Why using file-png-save2 instead of gimp-file-save? I noticed that using the first one don't export layer applying mask. gimp-file-save RUN-WITH-LAST-VALS do it but not RUN-NONINTERACTIVE.

Thanks :)


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Tue Nov 27, 2012 8:07 am  (#14) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
pitibalrog wrote:
And this two function returns something like (3 #(55, 32, 25)). If I have only one layer it returns (1 #(55)) and (0 #()) for empty group.
So I think I have to do cadr everytime to get the real list and not the count.

You are correct; I was mistaken. I tend to convert everything to lists and didn't notice that you were processing the "array" of layers (in Scheme parlance, such an array is called a "vector"; not to be confused with GIMP's 'vectors' terminology for paths).

pitibalrog wrote:
Some more questions I have about your code:
1) Where can I find the complete list of possible parasites like "gimp-comment"?

Parasites are user-defined "properties" that can be attached to various GIMP entities. The "gimp-comment" parasite is one of the few that is actually recognized by GIMP (when attached to an image being exported, it will be included as the file comment if supported by the targeted file format).

More generally, parasites provide a good way of associating data with an image, drawable, path, or the GIMP program itself. For example, the GFIG plug-in ("Filters->Render-Gfig") attaches a parasite to the generated layer that permits you to go back later and edit the shapes on the layer. In this script, I use a parasite so that the user can initially set some defaults for adding a watermark to an image, and then subsequently add that watermark to other images without being prompted.

pitibalrog wrote:
2) Why using file-png-save2 instead of gimp-file-save? I noticed that using the first one don't export layer applying mask. gimp-file-save RUN-WITH-LAST-VALS do it but not RUN-NONINTERACTIVE.

Using the 'file-*-save' plug-ins allows me to explicitly specify the various parameters, rather than having the defaults used (the user may have set the defaults to something suboptimal for my purposes). In this case, the user may have changed his default for PNG files such that the comment is not included.

You are correct that my script fails to account for layermasks; this should need be addressed in a future version. I would probably tend toward saving the mask as a separate file, but you may wish instead to have it applied before saving.

I added the 'gimp-progress-end' at the end of my script just to cleanup the status line; sometimes it will get "stuck" showing the last operation. Generally, progress should be displayed executing 'gimp-progress-update', or at least 'gimp-progress-pulse', within your program's looping code -- I was lazy and did not do this.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Tue Nov 27, 2012 10:09 am  (#15) 
Offline
GimpChat Member

Joined: Nov 26, 2012
Posts: 10
Thank you for this detailled answer. :)

For the mask do you know how to apply it in the script? I can do this in my code because i'm copying the original image.


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Tue Nov 27, 2012 11:34 am  (#16) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Use 'gimp-layer-remove-mask'

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Tue Nov 27, 2012 11:41 am  (#17) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
pitibalrog wrote:
Thanks for the link, there's a lot of ressources

I'm started trying to understand scheme with car, cdr, cadr...

But if Ofnuts or Saulgoode can help later I'll wait :-)

Not with Scheme for me... Scheme is to programming what wet plates are to photography: aesthetically pleasing, historically valuable, but we have got vastly better these days (*).

(*) Interestingly, my son started college this year (Math/CompSci) and their first programming class is in Scheme... with a very funny rationale: the professors want everybody to be on an equal standing, and think that while 1st year students with some C or Python skills abound, none will ever have learned Scheme before...

_________________
Image


Top
 Post subject: Re: Export layers as img with group handling
PostPosted: Tue Nov 27, 2012 4:51 pm  (#18) 
Offline
GimpChat Member

Joined: Nov 26, 2012
Posts: 10
@saulgoode: remove-mask ... I understand why I didńt find this. It´s ont natural for me. I was searching apply or merge...

@ofnuts: yes it´s possible with scheme. Saulgoode give me an example. Good luck for your son with scheme :-)


Top
Post new topic Reply to topic  [ 18 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Export Layers - new features

2

No new posts Attachment(s) Export as layers not working

5

No new posts Attachment(s) Export Layers by Khalim19 as batch action proces.

3

No new posts Copy Layer Group (SOLVED)

0

No new posts Shortcuts to 2.10 documentation re: Layer & Layer-group modes

0



* Login  



Powered by phpBB3 © phpBB Group