After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 304399 - Color Palette Export to TXT, CSS, XML, or XHTML
Color Palette Export to TXT, CSS, XML, or XHTML
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: User Interface
unspecified
Other All
: Low enhancement
: 2.8
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2005-05-16 18:28 UTC by J. Becker
Modified: 2009-08-02 13:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
A script-fu export framework (18.90 KB, patch)
2009-05-15 21:19 UTC, LightningIsMyName
none Details | Review
A git patch with the new script (19.96 KB, patch)
2009-07-19 07:42 UTC, LightningIsMyName
none Details | Review
A fixed version of the git patch (19.99 KB, patch)
2009-07-21 07:14 UTC, LightningIsMyName
none Details | Review
0001-Bug-304399-Color-Palette-Export-to-TXT-CSS-XML.patch (20.25 KB, patch)
2009-07-22 17:02 UTC, Martin Nordholts
needs-work Details | Review
Another git patch. Fixed the gui to autoselect a palette (22.35 KB, patch)
2009-07-28 06:34 UTC, LightningIsMyName
needs-work Details | Review
Fixed palette export patch (22.10 KB, patch)
2009-08-02 12:52 UTC, LightningIsMyName
none Details | Review

Description J. Becker 2005-05-16 18:28:15 UTC
When doing web development, the color palette tool is invaluable to quickly   
pull up colors and work with them in an image. A quick and dirty export   
function to dump the color values in a palette to a text file would be really  
helpful. An import feature would be a really nice addition too. 
 
Everyone loves the Gimp! 
 
color palette enhancement wishlist xml xhtml css text export import
Comment 1 weskaggs 2005-05-16 18:42:31 UTC
Perhaps you could clarify what you want.  When you save a palette, the result
(called something.gpl and saved by default in the "palettes" directory of your
personal GIMP directory) is in fact a text file in a very simple format.  This
meets your request as you have stated it -- however you didn't say anything
about css, xml, or xhtml beyond listing them as keywords.
Comment 2 J. Becker 2005-05-16 19:37:46 UTC
Perhaps menu entries to export to file as follows:  
 
Export to PHP:  
<?php 
$colors={ 
'aqua' => '#0ffba', 
'darkblue' => '#0597a', 
'green' => '#0b181', 
'mediumblue' => '#081b1', 
'rainyday' => '#e5e5e5', 
'skyblue' => '#0baff', 
'tan' => '#f4f6d1', 
'white' => '#ffffff', 
'yellow' => '#ffdc40' 
} 
?>  
  
Export to Python:  
colors={'skyblue': '#0baff', 'rainyday': '#e5e5e5', 'darkblue': '#0597a',  
'aqua': '#0ffba', 'yellow': '#ffdc40', 'mediumblue': '#081b1', 'green':  
'#0b181', 'tan': '#f4f6d1', 'white': '#ffffff'}  
  
Export to CSS: 
.aqua { color: '#0ffba' } 
.darkblue { color: '#0597a' } 
.green { color: '#0b181' } 
.mediumblue { color: '#081b1' } 
.rainyday { color: '#e5e5e5' } 
.skyblue { color: '#0baff' } 
.tan { color: '#f4f6d1' } 
.white { color: '#ffffff' } 
.yellow { color: '#ffdc40' } 
 
You're right. here's my work so far on just getting the colors into my python  
scripts... I don't know the ins and outs of Python-Fu or I'd contribute some 
code. 
 
colors={  
  'tan':(244,246,209),  
  'rainyday':(229,229,229),  
  'white':(255,255,255),  
  'skyblue':(0,186,255),  
  'mediumblue':(0,129,177),  
  'green':(0,177,129),  
  'aqua':(0,255,186),  
  'darkblue':(0,89,122),  
  'yellow':(255,220,64),  
}  
  
hexcolors={}  
for name,color in colors.items(): # convert colors to hex  
  hexcolors[name]='#'+''.join([hex(elem)[2:] for elem in color])  
  
print hexcolors  
{'skyblue': '#0baff', 'rainyday': '#e5e5e5', 'darkblue': '#0597a', 'aqua':  
'#0ffba', 'yellow': '#ffdc40', 'mediumblue': '#081b1', 'green': '#0b181',  
'tan': '#f4f6d1', 'white': '#ffffff'}  
  
 
Comment 3 Michael Schumacher 2005-05-17 08:16:00 UTC
Well, write such a script and put it on http://registry.gimp.org - it doesn't
even have to be a GIMP plug-in/script, just easy text transforms.
Comment 4 weskaggs 2005-05-17 15:34:01 UTC
Yes, a contribution would be welcome here.  Removing NEEDINFO because the
requested info has been provided.
Comment 5 Sven Neumann 2005-05-18 00:14:03 UTC
GIMP provides the API to write such a script so there doesn't need to be an
enhancement request for it.
Comment 6 J. Becker 2005-05-18 01:58:56 UTC
An API to write a script does not produce the script, so reopening as 
enhancement request. I'll write the code to do the transformations if someone 
can convert it to a gimpism for me. 
Comment 7 Sven Neumann 2005-05-18 09:14:38 UTC
I fail to see the general usefulness of this feature, so it should probably just
be a third-party script. That's why it doesn't need to be in our bug-tracker.
But perhaps you could enlighten me and explain why this would be an important
enhancement.
Comment 8 J. Becker 2005-05-18 12:42:48 UTC
Gotcha; well, since Gimp is frequently used for web development, the colors 
that are in a palette will become an important part of a web page. For example, 
if I'm developing a web page that has four or five principal colors (ex two 
shades of tan, green, blue, etc) I have to copy and paste the colors from the 
color selection dialog individually into HTML or CSS or whatever. Frequently I 
change the colors as well. I normally slice the page design up using guides and 
then paste as new image (come to think of it, another great feature would be to 
save the current selection as...), but large portions of the page are normally 
a solid color and it's more efficient to use HTML tables or CSS to draw those 
colors. 
 
Right now it's a manual process to get the colors out of Gimp (where you can 
play with the colors and find a good combo) and onto the HTML page. Since Gimp 
already has the colors in a great palette tool, it's a natural extension to 
export the palette. Dumping them in PHP, Python, and CSS is just a few lines 
more and easy to do. I don't know if this is an important enhancement, but it 
is a small feature, shouldn't impact existing code, and probably prove useful 
to web designers once they become aware of its existence. What do you think? 
Comment 9 weskaggs 2005-05-18 15:16:34 UTC
My personal opinion is that an option for saving in some kind of standard
palette file format, with a specification accessible from somewhere, might be a
good option for inclusion with GIMP.  An option for writing out the palette in a
nonstandard way, even if it is useful, would best be handled as a third-party
thing.  In any case removing NEEDINFO because the requested information has been
provided.
Comment 10 Manish Singh 2005-05-18 18:13:24 UTC
I don't think a standard palette file format exists.

The GIMP palette format is a simple text file, and can be a parsed in a tiny
amount of code in any scripting language. The reporter did not make a case for
this functionality to be in GIMP itself. Setting to NEEDINFO so he can explain.
Comment 11 J. Becker 2005-05-18 19:55:59 UTC
I agree; you have a good point in that we could have requests for palettes to 
be exported in a million formats since there isn't a standard format. On the 
other hand, as you point out, it's a tiny amount of code to set up filters for 
that. 
 
There's no menu-driven way to get the colors out of the Gimp. I didn't even 
realize that the colors were in the palette file as you noted until after I 
originally posted -- I simply guessed that the palette files were most likely 
in a plain-text format and went digging, since this is open source and that's 
how we do things. ;-) 
 
Since the palette color codes are few and simple, it's actually more work (even 
if a user had the expertise) to mangle the colors into the scripting language 
of choice than simply to copy and paste the hex codes. A nice menu-based export 
would make this feature accessible to those of us who aren't scripters -- and 
that includes a lot of the users who use the Gimp, most likely... since the 
amount of code to make a nice export is trivial, is there any reason not to 
make this feature addition? 
Comment 12 Sven Neumann 2005-05-19 21:21:03 UTC
Noone said that this feature shouldn't be added, only that it should not be part
of the GIMP core because it is not a tiny amount of code and mainly because
there's no standard format to export to. If there was one, we would use that as
the native format for palettes.
Comment 13 J. Becker 2005-05-19 21:29:17 UTC
Ok; if you want me to write up the code for export to several formats since 
there isn't a standard format, let me know. 
Comment 14 Michael Schumacher 2005-07-05 22:46:05 UTC
Jamie, did you write anything yet? I don't recall any related additions to the
registry.
Comment 15 Michael Schumacher 2006-01-12 19:09:41 UTC
I'll remove NEEDINFO to make this bug show up in normal searches again. Maybe someone else wants to add this.
Comment 16 LightningIsMyName 2009-05-15 21:19:14 UTC
Created attachment 134735 [details] [review]
A script-fu export framework

A script-fu script which implements various exporters (css, java, raw text, python and php) that are built on one export framework which I wrote.

Adding new exporters like this is a matter of minutes for anyone who has basic knowledge of scheme - this should be enough for everybody =)
since I can't include every possible variation people want, I have created this template, and the file itself contains comments that can teach you how to create more exporters.
Comment 17 LightningIsMyName 2009-07-19 07:42:32 UTC
Created attachment 138723 [details] [review]
A git patch with the new script

As requested in the mailing list, I added the patch as a git patch.
Comment 18 LightningIsMyName 2009-07-21 07:14:08 UTC
Created attachment 138888 [details] [review]
A fixed version of the git patch

Since my other git patches from that day had a bug for some reason, I'm not taking any chances - I recreated the patch.
Comment 19 Martin Nordholts 2009-07-22 17:02:31 UTC
Created attachment 139011 [details] [review]
0001-Bug-304399-Color-Palette-Export-to-TXT-CSS-XML.patch

Thanks, this works quite nice already, but before we can commit this I would like it to behave a bit better UI-wise:

* The palette I click on to invoke the exporter needs to be preselected
* I think being able to chose the palette inside the dialog is confusing, the selection has already been done by the right-click and the ability to pick a palette from within the dialog should be removed
* There should be a default name suggested, not just the extension. Using the palette-name.[ext] is sane default.
* As a bonus it would be nice if you could make the lines shorter in the script, some lines are very long and one of them is longer than 320 chars.

I have a attached a patch where I have removed trailing whitespace, converted to UNIX line endings and added the file to Makefile.am.
Comment 20 Martin Nordholts 2009-07-22 17:03:01 UTC
Let's get this into 2.8, it's nice to have.
Comment 21 LightningIsMyName 2009-07-23 07:08:36 UTC
Hello Martin,

"The palette I click on to invoke the exporter needs to be preselected" - This can be easily fixed
"I think being able to chose the palette inside the dialog is confusing, the
selection has already been done by the right-click and the ability to pick a
palette from within the dialog should be removed" - Again, this can be easily fixed
"As a bonus it would be nice if you could make the lines shorter in the
script, some lines are very long and one of them is longer than 320 chars." - Done

"There should be a default name suggested, not just the extension. Using the
palette-name.[ext] is sane default." - Here we have a problem.
The call for script-fu-register is performed only once, so If I add a call for (gimp-context-get-palette) when registering the script, like so:

SF-STRING "The name of the file to create" (string-append (car (gimp-context-get-palette)) "." file-type)

It still won't fix the problem. The suggested name will be the default palette when the script was registered, and it won't update.

The only possible fix for that problem, is to change the plugin to a proper plugin language (C) which can create it's own dialogs and respond to custom events (such as showing the dialog again).
I can do that, while still keeping a way to alow the users to create a custom export (I'll create a procedure plug-in-export-palette-full which can be invoked from scripts to create custom exporters, This way we won't loose the flexibility of scripts).

Do we want a proper C plugin (I have no problem writing one), or do we want to keep it as a script while giving up the file-name suggestion feature?
Comment 22 Martin Nordholts 2009-07-23 07:24:25 UTC
It would be nice to have a better name suggestion, but at the same time I wonder if it is really worth the effort for you. I think it would be fine to just change the default name to "exported-palette.ext" instead of just ".ext". Instead of rewriting the plug-in I would rather see extended script-fu capabilities to support the default name suggestion feature, but that can be investigated some other time.
Comment 23 LightningIsMyName 2009-07-23 08:46:26 UTC
I fixed the script, and I'll submit the patch on sunday (When I get to a computer with git).
Comment 24 LightningIsMyName 2009-07-28 06:34:29 UTC
Created attachment 139352 [details] [review]
Another git patch. Fixed the gui to autoselect a palette

Here is the fixed version of the script.
I shortened up the lines of code to a readable length, I added a bit more inline documentation to make it even easier to add new exporters, and finally I made the script autoselect the active palette.
Comment 25 Martin Nordholts 2009-08-01 07:55:26 UTC
Thanks

It has problems though

 * At least the Java export doesn't seem to work
 * The export formats are grouped with a separator below "css..." which
   is confusing, grouping doesn't make sense
 * It turns out "default-pallete.ext" is too long to fit in the entry,
   let's change it to just "palette.ext"
 * You re-introduced windows line endings
 * You re-introduced trailing white space
Comment 26 LightningIsMyName 2009-08-01 16:10:53 UTC
Hello Martin,

"You re-introduced windows line endings" - Took me a while to understand what this means, and now I see the problem. I'll take care of it.
"You re-introduced trailing white space" - I use PLT scheme, apeerantly it does this automatic when it edits my scheme code... I'll fix that to.
"At least the Java export doesn't seem to work" - I caused a little bug when doing the previous fix :D I know fixed it (it affected the python export and the java export).
"The export formats are grouped with a separator below "css..."" - Took me some time to figure out what is the cause of that, but it's fixed now.

Tomorrow I'll get to a computer with git to resubmit the patch.
Comment 27 LightningIsMyName 2009-08-02 12:52:03 UTC
Created attachment 139730 [details] [review]
Fixed palette export patch

Hello again,

I converted the windows line endings to unix line endings, removed trailing spaces and fixed all the bugs. Hopefully, for the last time =)
Comment 28 Martin Nordholts 2009-08-02 13:11:14 UTC
Thanks, this seems to work good enough now, I've pushed your commit and am closing this enhancement request as FIXED.

commit e7e5a6d19d100ac1b4a70ac6446e00712538a2a3
Author: Barak Itkin <lightningismyname@gmail.com>
Date:   Sun Aug 2 15:30:57 2009 +0300

    Bug 304399 – Color Palette Export to TXT, CSS, XML, or XHTML

    Add a palette export script which allows exporting palettes to .css,
    .php, .py, .txt and .java by adding a Export to menu item in the
    palette context menu in the Palettes dockable.

 plug-ins/script-fu/scripts/Makefile.am        |    1 +
 plug-ins/script-fu/scripts/palette-export.scm |  432 +++++++++++++++++++++++++
 2 files changed, 433 insertions(+), 0 deletions(-)