It is currently Fri Apr 19, 2024 7:19 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Mon Jan 10, 2011 6:52 pm  (#1) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
I know well that are several similar script but none may do what i need

The script should export all layers of a xcf as png(or jpg ) using the Layer names as name for the new images
In case 2 names identical should add a progressive numeric prefix (or post fix ) to avoid overwriting

The names to use may be pretty long, this is a layer name

[G'MIC] Graphic Novel FX : -gimp_photocomix_booost2 1,4.36364,10.4727,5,20,0.12,14,0,0.5,0.54,2.90909,9,0.936364,1,0.5,0.54,0.78

that should become

[G'MIC] Graphic Novel FX : -gimp_photocomix_booost2 1,4.36364,10.4727,5,20,0.12,14,0,0.5,0.54,2.90909,9,0.936364,1,0.5,0.54,0.78.png

or in case another layer already saved with same name

1_[G'MIC] Graphic Novel FX : -gimp_photocomix_booost2 1,4.36364,10.4727,5,20,0.12,14,0,0.5,0.54,2.90909,9,0.936364,1,0.5,0.54,0.78.png

In many cases i strictly need only the first part as
[G'MIC] Graphic Novel FX : -gimp_photocomix_booost2 .png
but would be much better if all the name used without shortening

a xcf with similar long names is here

http://www.box.net/shared/sfslkllqoa

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


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: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Tue Jan 11, 2011 5:17 am  (#2) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Do you care if the solution is a script-fu script or a python script? and what do you want to happen if the layer name has characters in that aren't allowed in filenames - "/ \ < > | * ? :"

Where you you like to continue this discussion? Here or on http://www.gimptalk.com/forum/posting.php?mode=reply&f=9&t=51356&sid=cc6722b97405d5c7d1c579c717bb299a

For preference I'd say here as GimpTalk continues to be unreliable.

_________________
Kevin


Top
 Post subject: Re: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Tue Jan 11, 2011 5:39 am  (#3) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
Thank Paynekj ...here is fine
No problem if python or script fu i may well use both

Filename may contain ": - ., []"
So if ":" is forbidden i fear should be replaced by ...huumm "ç" or "@" are allowed in image names ?

the other characters may be normal letters, numbers and "-.,[]" I hope those last all permitted

I will use not only for image modified with gmic, but in all other cases names will be more "normal"

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Tue Jan 11, 2011 6:40 am  (#4) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Here's a good article about illegal characters in filenames:
http://linuxboxadmin.com/articles/tools-and-utilities/linux/mac/windows-file-name-friction.html and it does also raise the point about the full path on Windows must be at most 255 characters.

How about I change the colon ":" into a semi-colon ";" ? I think the @ would be OK, but I'm not sure about "ç" (is it ASCII character 231?)

If you save a layer manually, what settings do you use in the PNG file save dialog?
Interlacing, Save background color, Save gamma, Save layer offset, Save resolution, Save creation time, Save comment, preserve color of transparant pixels, and compression level

_________________
Kevin


Top
 Post subject: Re: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Tue Jan 11, 2011 7:15 am  (#5) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
How about I change the colon ":" into a semi-colon ";" ?

Perfect !

f you save a layer manually, what settings do you use in the PNG file save dialog?
Interlacing, Save background color, Save gamma, Save layer offset, Save resolution, Save creation time, Save comment, preserve color of transparant pixels, and compression level



Interlacing, Save background color, Save gamma, Save layer offset = False
Save resolution, Save creation time, Save comment, preserve color of transparant pixels =True
compression level= max (9)

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Wed Jan 12, 2011 5:36 am  (#6) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Hopefully this will do what you want. I tried to attach it to this post but I got the nasty message: The extension py is not allowed :gaah so here it is as code:

#!/usr/bin/env python
# Author: Kevin Payne
# Copyright 2011 Kevin Payne
# License: GPL v3
# GIMP plugin to export the layers of an .xcf as png images
#  each png file has the name of the layer
# For PhotoComix:- http://gimpchat.com/viewtopic.php?f=9&t=985

from gimpfu import *
import os.path
import pygtk
import gtk

# something to help with debugging
def debugMessage(Message):
    dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, Message)
    dialog.run()
    dialog.hide()

# unique_filename from http://stackoverflow.com/questions/183480/is-this-the-best-way-to-get-unique-version-of-filename-w-python
def unique_filename(file_name):
    counter = 1
    file_name_parts = os.path.splitext(file_name) # returns ('/path/file', '.ext')
    while os.path.isfile(file_name):
      file_name = file_name_parts[0] + '_' + str(counter) + file_name_parts[1]
      counter += 1
    return file_name

# this is the bit that does all the work
def export_layers_as_png(img):
    layer_ids = img.layers                         # get the layers in the image
    directory_name = os.path.dirname(img.filename) # where is the source image
   
#    debugMessage(directory_name)
   
    num_layers = len(layer_ids)                   
    for layer_num in range (0, num_layers):        # work through layers (change to "num_layers-1" if you don't want the bottom layer)
      layer_name = pdb.gimp_drawable_get_name(layer_ids[layer_num]) 
#      debugMessage(layer_name)
     
      # replace any illegal characters to be on the safe side
      layer_name = layer_name.replace(":", ";")
      layer_name = layer_name.replace("/", ";")
      layer_name = layer_name.replace("\\", ";")
      layer_name = layer_name.replace("?", ";")
      layer_name = layer_name.replace("*", ";")
      layer_name = layer_name.replace("\"", ";")
     
#      debugMessage(layer_name)

      # build the new file path - puts the saved layers in the same place as the source image
      png_file = os.path.join(directory_name, layer_name + ".png")
      png_file = unique_filename(png_file)

#      debugMessage(png_file)     
      pdb.file_png_save2(img, layer_ids[layer_num], png_file, png_file, 1, 9, 1, 1, 0, 1, 1, 1, 1)

      # The End of the main routine


# menu registration
register(
    "python-fu-export-layers-as-png",
    "Export Layers as PNGs",
    "Export Layers as PNGs",
    "paynekj",
    "GimpChat",
    "12.01.2011",
    "Export Layers as separate PNGs",
    "*",
    [
         (PF_IMAGE, "image",       "Input image", None),
    ],
    [],
    export_layers_as_png,
    menu="<Image>/contributed/"
    )

main()


It's python, and you know where to put pythons ;)
The menu entry is under "contributed" because I'd rather you decide where you want to put it.

_________________
Kevin


Top
 Post subject: Re: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Wed Jan 12, 2011 6:15 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Awesome, i have mine set to open in the File menu.
Thanks paynekj. =)

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Wed Jan 12, 2011 2:34 pm  (#8) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
thank Kevin i am installing now

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Wed Jan 12, 2011 3:17 pm  (#9) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4045
Thanks, Kevin! :)

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Wed Jan 12, 2011 5:01 pm  (#10) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
PERFECT !! :yes :jumpclap

Thank a lot Kevin, i had a dumb moment (at first i saved as scm :lol ) but the script works as a charm :wow

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Wed Jan 12, 2011 11:40 pm  (#11) 
Offline
Former Member
User avatar

Joined: Nov 17, 2010
Posts: 618
Location: Rockford, IL
Here's two scripts I have on my Linux machine here, maybe they should help you out.

Attachment:
savealllayers.zip [4 KiB]
Downloaded 276 times


Top
 Post subject: Re: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Thu Jan 13, 2011 6:31 am  (#12) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
Thank Mike but i was needing a new script and paynekj solved well , the whole point was save the layer names as names of the png, and deal with possible special characters that are often present in that names

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: Hoping for a " Export Layers as png (or jpg) script"
PostPosted: Thu Jan 13, 2011 2:58 pm  (#13) 
Offline
Former Member
User avatar

Joined: Nov 17, 2010
Posts: 618
Location: Rockford, IL
oh ok


Top
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


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

5

No new posts Attachment(s) Export Layers - new features

2

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

3

No new posts Attachment(s) Batch export all opened images script for GIMP [Update]

13

No new posts Attachment(s) Shortening mouse/keystrokes save/export script or method to implement?

41



* Login  



Powered by phpBB3 © phpBB Group