Post Reply 

Scripting in GIMP - automating a common task.

Jan 12, 2012, 01:06
Post: #1
Scripting in GIMP - automating a common task.
I have been using GIMP as my main image editing application for some time now. But I have never used any scripts with the program. However, I do have an extensive background with Ruby and VBS.

I am wanting to automate a task, for the purpose of making it easier for someone else to complete - without going into the details (with them) of how I do it (myself) manually.

I start out with three "1 bit" bitmaps, created by another application from Gerber files. The bitmaps are usually Black on White, but White on Black is an option too.

I open them one at a time with GIMP, and perform the following tasks. (Lately, the Image Mode has been set to Indexing..., instead of RGB, when I open GIMP, but that is beside the point - for now anyway.)

Image 1 - select background, color-to-alpha, save as PNG - done.
Image 2 - select foreground, color-to-alpha, select background, pick a color (green) > Edit > Fill with FG color, save as PNG - done.
Image 3 - select background, color-to-alpha, select foreground, pick a color (brown) > Edit > Fill with FG color, save as PNG - done.

The resulting PNG images are then imported as textures into another application, via a Ruby Script (PlugIn).

I know this can all be done with ImageMagick/RMagick, and I fully intend to implement that down the road - I just want to preemptively relieve any burden, there may be on the learning curve of my users, as well as make the process's cumulative footprint as small as possible during development.

Thank you in advance for any suggestions.
Find all posts by this user
Quote this message in a reply
Jan 12, 2012, 01:40
Post: #2
RE: Scripting in GIMP - automating a common task.
I don't see the point of going through Gimp if you already know you can do it with ImageMagick.

And if you want to do it in Gimp, do it properly. After selecting what you want to remove by color to apha, grow the selection by one pixel to cover the anti-aliasing pixels. Handling these pixels is the main purpose of color-to-alpha. And for images 2 and 3, the anti-aliasing pixels wont be colored properly by your technique because they won't be selected before applying paint. You should instead lock the alpha-channel and bucket-fill the whole image.

See http://gimpforums.com/thread-proper-subj...d-painting for the full story.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Jan 12, 2012, 02:41
Post: #3
RE: Scripting in GIMP - automating a common task.
The point of going through GIMP, is to allow users to the opportunity to use my application now. Implementing IM/RM is going to take some time, as I need to work on other more pressing aspects of my app at the present. There also remains a slight chance that IM/RM won't work at all... dunno, I haven't gotten that far.

The point of wanting to script the process for now, is to make it as close to a point and click, as I can - while providing as little tech support for GIMP as possible, as well as avoiding any unnecessary dependencies, that ultimately come with and more often than not, hamper usability as a whole, when using multiple applications in succession. (Right now the count is 6, including GIMP.)

The anti-aliasing pixel is a non issue, as the resulting PNG images look fine as-is, as well as being a temporary form/function at that. (In other words - I don't care if the current method of creating PNG images is imperfect - the results are satisfactory, for how they are used.)

I just want to make the current process as simple for my users as possible - that's all.

Your suggestions on improving my current method, are testament as to why I want to script the current process - I don't want to teach my users how to use GIMP, partly because it's not intended to be part of the bigger picture anyway, "and" if it ends up being a permanent part of the process - I want control of how it's implemented and maintained - not, "you didn't do this or you need to do that."
Find all posts by this user
Quote this message in a reply
Jan 12, 2012, 11:32
Post: #4
RE: Scripting in GIMP - automating a common task.
You've explained your process fairly well, but you haven't said what parts you need automating.

Do you expect your users to specify the input files, then press "GO" and have the three PNG files then made without further intervention? because I then have to ask how you determine the foreground/background colours.

Kevin
Find all posts by this user
Quote this message in a reply
Jan 12, 2012, 19:59
Post: #5
RE: Scripting in GIMP - automating a common task.
As stated in my first post, I want to automate the part that I do manually. All three source files, have a different descriptive name for each image, that will not change from user to user - so at the very least, it could be 3 scripts, one for each image (Like a macro in excel...). The foreground and background colors are as stated as well - it's not a hypothetical - that's the actual scheme. Image 1 has the background set to alpha and foreground left as-is, Image 2 has the foreground set to alpha and the background colored green, Image 3 has the background set to alpha and the foreground colored brown.

If I can get away with a command line argument, that does them as a batch, that would be OK too...
Find all posts by this user
Quote this message in a reply
Jan 12, 2012, 20:41
Post: #6
RE: Scripting in GIMP - automating a common task.
(Jan 12, 2012 19:59)tahwos Wrote:  As stated in my first post, I want to automate the part that I do manually. All three source files, have a different descriptive name for each image, that will not change from user to user - so at the very least, it could be 3 scripts, one for each image (Like a macro in excel...). The foreground and background colors are as stated as well - it's not a hypothetical - that's the actual scheme. Image 1 has the background set to alpha and foreground left as-is, Image 2 has the foreground set to alpha and the background colored green, Image 3 has the background set to alpha and the foreground colored brown.

If I can get away with a command line argument, that does them as a batch, that would be OK too...
if the background can be identified by some heuristic (for instance, 3 or 4 of the corner pixels have the same color) then it isn't hard, everything can be done using the selection on the background, and its inverse.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Jan 12, 2012, 21:48
Post: #7
RE: Scripting in GIMP - automating a common task.
Sorry to quote your own words back at you, but you're being contradictory
(Jan 12, 2012 19:59)tahwos Wrote:  The foreground and background colors are as stated as well

But you originally said
(Jan 12, 2012 01:06)tahwos Wrote:  The bitmaps are usually Black on White, but White on Black is an option too.

So I asked if you need to ask the user what the foreground colour is: Black or White? or is Ofnuts' method a viable way of automatically picking the background colour?

So you have three input files with fixed names? So you don't need the user to be able to interactively pick which files to use? And how are the names of the output files defined. Are they also fixed?
For example, you always have exactly file1.bmp, file2.bmp and file3.bmp as inputs and expect to get file1.png, file2.png and file3.png as outputs.

Do you want the users to be able to choose the "green" and "brown" colours? or are they fixed: i.e #00FF00 and #4b0f0f for example.

By asking these questions all I'm trying to do is to get you to specify your requirements unambiguously.

Kevin
Find all posts by this user
Quote this message in a reply
Jan 13, 2012, 02:28
Post: #8
RE: Scripting in GIMP - automating a common task.
(Jan 12, 2012 20:41)ofnuts Wrote:  if the background can be identified by some heuristic (for instance, 3 or 4 of the corner pixels have the same color) then it isn't hard, everything can be done using the selection on the background, and its inverse.

It his highly unlikely, that the group of source images, will have the foreground color in the corners - but it is still possible. Can't I just select by color and/or foreground/background, then go from there? (Like I do manually.)
Find all posts by this user
Quote this message in a reply
Jan 13, 2012, 02:54
Post: #9
RE: Scripting in GIMP - automating a common task.
(Jan 12, 2012 21:48)paynekj Wrote:  Sorry to quote your own words back at you, but you're being contradictory
(Jan 12, 2012 19:59)tahwos Wrote:  The foreground and background colors are as stated as well

But you originally said
(Jan 12, 2012 01:06)tahwos Wrote:  The bitmaps are usually Black on White, but White on Black is an option too.

So I asked if you need to ask the user what the foreground colour is: Black or White? or is Ofnuts' method a viable way of automatically picking the background colour?

So you have three input files with fixed names? So you don't need the user to be able to interactively pick which files to use? And how are the names of the output files defined. Are they also fixed?
For example, you always have exactly file1.bmp, file2.bmp and file3.bmp as inputs and expect to get file1.png, file2.png and file3.png as outputs.

Do you want the users to be able to choose the "green" and "brown" colours? or are they fixed: i.e #00FF00 and #4b0f0f for example.

By asking these questions all I'm trying to do is to get you to specify your requirements unambiguously.

Kevin

In a nutshell - you're over thinking it.

The foreground/background colors that were stated, was referring to the green background needed for Image 2 PNG, and the brown foreground for Image 3 PNG.

The Black on White BMP or White on Black BMP options, information was stated just for the sake of clarifying user options in my original question - just in case one yielded an easier resolution than the other, nothing more (In other words - this is what they "can" do.). In reality, if the user chose to do so (In the source application), they could create the bitmaps one at a time, with every other one inverted black/white, and so on.

The file names are static - image1.bmp, image2.bmp, image3.bmp > image1.png, image2.png, image3.png.

For the time being - the colors are chosen by me, but I will provide information on tweaking the script, to the user. i.e. hex as you mentioned.
Find all posts by this user
Quote this message in a reply
Jan 13, 2012, 10:40
Post: #10
RE: Scripting in GIMP - automating a common task.
(Jan 13, 2012 02:54)tahwos Wrote:  In a nutshell - you're over thinking it.

I think you're wrong. Clarifying your requirements is hardly over thinking.

However I've got over my irritation with your lack of clarity and knocked-off a basic script.

I've attached a zip file with the GIMP script, a DOS-Batch file to show how to run it from the command line and the test files I used.

As you didn't state what options you have selected when saving the PNG files, I've assumed the GIMP defaults. (more overthinking?)

Good luck

Kevin


Attached File(s)
.zip  tahwos.zip (Size: 7.09 KB / Downloads: 152)
Find all posts by this user
Quote this message in a reply
Jan 14, 2012, 01:43
Post: #11
RE: Scripting in GIMP - automating a common task.
That's quite enough to get me pointed in the right direction - Thank You!

And no, assuming defaults is never over-thinking. In your earlier post, you seemed to get the available input file options, confused with the desired output file results, which could have been avoided, if I had just posted sample files to begin with - "this is what got >>> this is what I want".

btw...
Assuming it was for electronics, and that they were PCB layers, was also correct on your part.

Thanks Again - I'll make sure to credit you in the code, as well as the release. PM me if you have a preference of syntax - otherwise, I'll just link your profile on this forum.
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  plugin save for web in Gimp 2.9.6 Dkk 1 191 Oct 19, 2017 09:02
Last Post: paynekj
  Script-fu: How to create new, addressable layer using gimp-floating-sel-to-layer Bertholom√§us 2 231 Aug 31, 2017 14:32
Last Post: Bertholomäus
  Late binding / COM for opening an image into GIMP? i73 2 198 Aug 4, 2017 17:39
Last Post: i73
  Loading PythonFu Plugin: ImportError for .../python/gimp.so (GIMP 2.8.22/OSX/Py2.7.9) joroek 1 315 Jul 11, 2017 07:26
Last Post: ythgilb
  How to close gimp with batch command? flixe 1 295 Jun 19, 2017 12:29
Last Post: ythgilb

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS