Post Reply 

how to use the smudge tool in command line or script ?

Mar 5, 2014, 09:18 (This post was last modified: Mar 5, 2014 09:20 by mygost.)
Post: #1
how to use the smudge tool in command line or script ?
Hi everyone,

first : i don't know anything about scripting in GIMP Huh
and i want to script something like that should look like this :

smudge_tool (size, type, shape, [...], from (x1,y1), to (x2,y2) )
smudge_tool (size, type, shape, [...], from (x1,y1), to (x2,y2) )
[...]
smudge_tool (size, type, shape, [...], from (x1,y1), to (x2,y2) )

of course coordinates (x1,y1) & (x2,y2) would be differently customized hard coded on each line.

BUT i didn't find a way to use the smudge tool Smudge "command line" style
anyone have a clue, where the manual?
thanks

---------------------------------------------------------------------------------------------------------
the full automated script would look like :

for ('*.jpg' in 'folder') do (
open file_x.jpg
smudge_tool (size, type, shape, [...], from (x1,y1), to (x2,y2) )
smudge_tool (size, type, shape, [...], from (x1,y1), to (x2,y2) )
[...]
smudge_tool (size, type, shape, [...], from (x1,y1), to (x2,y2) )
save as file_x-new.jpg;
)

if anyone can write me in 2min the generic fu-script, python-script, any script for GIMP, you would save me hours of R&D.... Angel and drop by, beers are on me...

thanks
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 09:28
Post: #2
RE: how to use the smudge tool in command line or script ?
(Mar 5, 2014 09:18)mygost Wrote:  for ('*.jpg' in 'folder') do (
open file_x.jpg
smudge_tool (size, type, shape, [...], from (x1,y1), to (x2,y2) )
smudge_tool (size, type, shape, [...], from (x1,y1), to (x2,y2) )
[...]
smudge_tool (size, type, shape, [...], from (x1,y1), to (x2,y2) )
save as file_x-new.jpg;
)

should become something like :

gimp -i -b '(batch-smudge-tool_custom "*.jpg" param1, param2, param3[...])' -b '(gimp-quit 0)'
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 11:58 (This post was last modified: Mar 5, 2014 12:05 by mygost.)
Post: #3
RE: how to use the smudge tool in command line or script ?
(Mar 5, 2014 10:34)ofnuts Wrote:  See attached for an example of a batch script.

For the smudge tool:

pdb.gimp_smudge(drawable, pressure, num_strokes, strokes)
pdb.gimp_smudge_default(drawable, num_strokes, strokes)

for the complete documentation:

>Filters>Python-fu>Console

And then hit the "Browse..." button and enter (part of) the name if the function in the search field.

great great great !!!
now the ball starts rolling!!!

pb: i just get fail/success on python exec --> hard blind programming!!
how do i get a verbose output for the python exec ??
i don't even see the "print" outputs !

maybe to python "print" in an output file?

here is my output: (i verbosed the gimp exec)
---------------------------------------------------------------------------------------------------------------------------------------
INIT: gimp_load_config
Parsing 'C:\Users\user\.gimp-2.8\unitrc'
Parsing 'C:\Program Files\GIMP 2\etc\gimp\2.0\gimprc'
Parsing 'C:\Users\user\.gimp-2.8\gimprc'
gimp_composite: verbose=no
Processor instruction sets: +mmx +sse +sse2 -3dnow -altivec -vis
INIT: gimp_initialize
INIT: gimp_real_initialize
INIT: gimp_restore
Parsing 'C:\Users\user\.gimp-2.8\parasiterc'
Parsing 'C:\Users\user\.gimp-2.8\templaterc'
INIT: gimp_real_restore
Parsing 'C:\Users\user\.gimp-2.8\pluginrc'
Querying plug-in: 'C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins\pyconsole.py'
Initializing plug-in: 'C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins\layerfx.2.8
.py'
Initializing plug-in: 'C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins\btn4ws.py'
Writing 'C:\Users\user\.gimp-2.8\pluginrc'
Starting extension: 'extension-script-fu'
batch command executed successfully
EXIT: gimp_exit
EXIT: gimp_real_exit
Writing 'C:\Users\user\.gimp-2.8\templaterc'
Writing 'C:\Users\user\.gimp-2.8\parasiterc'
Writing 'C:\Users\user\.gimp-2.8\unitrc'
EXIT: batch_exit_after_callback
(Type any character to close this window)
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 13:13 (This post was last modified: Mar 5, 2014 13:14 by mygost.)
Post: #4
RE: how to use the smudge tool in command line or script ?
(Mar 5, 2014 12:43)paynekj Wrote:  The python "print" outputs (i.e. output to stdout) get sent into a black hole on Windows, and if you try and do too many of them it crashes the script. - Maybe you could create a log file to write to instead.

Kevin

yep that was one of my supposed solution...
>>maybe to python "print" in an output file?

but i don't know this python snake... and i don't have proper dvlp env... no output debugging right now... the snake biting its tail...

what would be the proper code line to make python send its output to a file.log ??

now the valid but non visible code i got is formated as :

print "Running on directory \"%s\"" % directory
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 13:35
Post: #5
RE: how to use the smudge tool in command line or script ?
(Mar 5, 2014 13:20)paynekj Wrote:  You would want to open the log file, write to it and when you are finished, close it:

Code:
logFile = open("my_log.txt", "w")

logFile.write("I made it this far\n")

logFile.write("Still going\n")

logFile.write("Running on directory \"%s\"" % directory )
    
logFile.close

yes your code is running OK
still i'll get only MY print out --> i don't get the python error output, i need it to debug my code tweaking... so it's just half a solution...

any idea to fully redirect all outputs print & error into the log file ??
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 13:41
Post: #6
RE: how to use the smudge tool in command line or script ?
thanks man, with your help, i'm almost half genius!!
got it fully by redirecting win batch...

"C:\Program Files\GIMP 2\bin\gimp-2.8.exe" --verbose -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import batch;batch.run('./images')" -b "pdb.gimp_quit(1)" > out.log 2>&1
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 13:53 (This post was last modified: Mar 5, 2014 13:53 by mygost.)
Post: #7
RE: how to use the smudge tool in command line or script ?
Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }

Arrggg what again???
i don't get it... how do i format a damnn FLOATARRAY ??

----------------------------------------------------------------------------------------------------
batch command experienced an execution error
Traceback (most recent call last):
File "C:\Program Files\GIMP 2\32\lib\gimp\2.0\python\gimpfu.py", line 777, in _run
return apply(func, params[1:])
File "C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins\python-eval.py", line 25, in code_eval
exec code in globals()
File "<string>", line 1, in <module>
File ".\batch.py", line 31, in run
process(infile)
File ".\batch.py", line 16, in process
pdb.gimp_smudge(drawable, 100, 2, {719,961,730,973} )
TypeError: wrong parameter type
EXIT: gimp_exit
EXIT: gimp_real_exit
----------------------------------------------------------------------------------------------------
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 14:23
Post: #8
RE: how to use the smudge tool in command line or script ?
(Mar 5, 2014 14:03)paynekj Wrote:  
Code:
pdb.gimp_smudge(drawable,100,4,[0,0,100,100])

Oh, and by the way you're trying to remove sensor dust not lens dirt.

Kevin

array ok...

truly i don't know which lens or sensor this damn spot belong to... any idea to clean up the stuff (smartphone camera... very compact,)

and any idea about the 0 effect the pdb.gimp_smudge(drawable,100,4,[0,0,100,100]) offers me??

how do i get an effect? any effect? this change nothing to anything...
i guess i don't understand the use of it...
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 14:44
Post: #9
RE: how to use the smudge tool in command line or script ?
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-

import os,glob,sys,time
from gimpfu import *


def process(infile):
print "Processing file %s " % infile
image = pdb.file_jpeg_load(infile,infile)
drawable = pdb.gimp_image_get_active_layer(image)

print "File %s loaded OK" % infile

# ref man: pdb.gimp_smudge(drawable, pressure, num_strokes, strokes)
pdb.gimp_smudge(drawable, 100, 4, [0,0,100,100] )

outfile=os.path.join('processed',os.path.basename(infile))
outfile=os.path.join(os.path.dirname(infile),outfile)
print "Saving to %s" % outfile
pdb.file_jpeg_save(image, drawable, outfile, outfile, "1",0,1,0,"",0,1,0,0)
print "Saved to %s" % outfile
pdb.gimp_image_delete(image)


def run(directory):
start=time.time()
print "Running on directory \"%s\"" % directory

for infile in glob.glob(os.path.join(directory, '*.jpg')):
process(infile)
end=time.time()
print "Finished, total processing time: %.2f seconds" % (end-start)


if __name__ == "__main__":
print "Running as __main__ with args: %s" % sys.argv
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 16:23
Post: #10
RE: how to use the smudge tool in command line or script ?
(Mar 5, 2014 15:31)paynekj Wrote:  I added in the bits to run it interactively, and I had to manually create the "processed" folder.

Kevin

sorry forgot to mention the "processed" folder Angel

alas it seems to completely fuck up windows calls back here and everywhere!!! [yeah, i'm getting bored... spending 1 day to zero results really piss me off AngryAngry ]

guess you run it on linux... hhmmm, guess i'll give up and buy a iMac... pfff bored bored bored... ConfusedConfused

yesterday in a huge metal bird flying half the world across plains, oceans, higher than the highest mountain on earth, half-drunk & happy...
today writing lines to make a stupid computer perform a few operations a 5 year old kid could do in 5min... with a tool called "mouse"
what a fucking crazy life!!!

i think i'll download a photoshop and play the record/replay scripting...
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 16:24
Post: #11
RE: how to use the smudge tool in command line or script ?
many thanks for your help and patience!!

would you come by near Nice (france), be welcome to get a beer in a setting sun...
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 17:57 (This post was last modified: Mar 5, 2014 17:58 by mygost.)
Post: #12
RE: how to use the smudge tool in command line or script ?
(Mar 5, 2014 17:43)ofnuts Wrote:  
(Mar 5, 2014 17:07)paynekj Wrote:  However, I've found that there's a difference between running interactively and from the command line. I suspect it's because of this:
Quote:This tool simulates a smudge using the current brush.
Which may mean that a brush needs to be selected first.

Code:
pdb.gimp_context_set_brush(name)

Yes you might be 100% right again...

i've added :
Code:
    pdb.gimp_context_set_brush_aspect_ratio(0)
    pdb.gimp_context_set_brush_angle(0)
    pdb.gimp_context_set_brush_size(20)    
    pdb.gimp_context_set_brush("2. Hardness 100")

but still got :
batch command experienced an execution error
Traceback (most recent call last):
File "C:\Program Files\GIMP 2\32\lib\gimp\2.0\python\gimpfu.py", line 777, in _run
return apply(func, params[1:])
File "C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins\python-eval.py", line 25, in code_eval
exec code in globals()
File "<string>", line 1, in <module>
File ".\batch.py", line 36, in run
process(infile)
File ".\batch.py", line 18, in process
pdb.gimp_context_set_brush("2. Hardness 100")
RuntimeError: Brush '2. Hardness 100' not found
EXIT: gimp_exit

using gimp in english... names are the same as you provided but UN-succesful Huh

did i miss a variable? a set? an include <> ??
seems so close.... to the next issue?? LOL

------------------------------------------------------------------------------------------
Code:
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-

import os,glob,sys,time
from gimpfu import *


def process(infile):
    print "Processing file %s " % infile
    image = pdb.file_jpeg_load(infile,infile)
    drawable = pdb.gimp_image_get_active_layer(image)

    print "File %s loaded OK" % infile

    pdb.gimp_context_set_brush_aspect_ratio(0)
    pdb.gimp_context_set_brush_angle(0)
    pdb.gimp_context_set_brush_size(20)    
    pdb.gimp_context_set_brush("2. Hardness 100")

    # ref man: pdb.gimp_smudge(drawable, pressure, num_strokes, strokes)    
    pdb.gimp_smudge(drawable, 100, 4, [0,0,100,100] )

    outfile=os.path.join('processed',os.path.basename(infile))
    outfile=os.path.join(os.path.dirname(infile),outfile)
    print "Saving to %s" % outfile
    pdb.file_jpeg_save(image, drawable, outfile, outfile, "1",0,1,0,"",0,1,0,0)
    print "Saved to %s" % outfile
    pdb.gimp_image_delete(image)


def run(directory):
    start=time.time()
    print "Running on directory \"%s\"" % directory

    for infile in glob.glob(os.path.join(directory, '*.jpg')):
        process(infile)
    end=time.time()
    print "Finished, total processing time: %.2f seconds" % (end-start)


if __name__ == "__main__":
    print "Running as __main__ with args: %s" % sys.argv
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 18:04 (This post was last modified: Mar 5, 2014 18:05 by mygost.)
Post: #13
RE: how to use the smudge tool in command line or script ?
weird, the console finds it HuhHuh :

Code:
GIMP 2.8.2 Python Console
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
>>> pdb.gimp_context_set_brush(2 Hardness 100)
  File "<input>", line 1
    pdb.gimp_context_set_brush(2 Hardness 100)
                                        ^
SyntaxError: invalid syntax

>>> pdb.gimp_context_set_brush("2. Hardness 100")
>>> pdb.gimp_context_set_brush('2. Hardness 100')
>>>
Find all posts by this user
Quote this message in a reply
Mar 6, 2014, 16:01
Post: #14
RE: how to use the smudge tool in command line or script ?
(Mar 5, 2014 18:44)paynekj Wrote:  Do you still have the -d option on your command line as this tells GIMP not to load brushes (among other things)?

right again...
[i've copy/paste a given cmd line without paying attention to it; as usual]

well now it's *working*, still the tool does not perform as i wish, it might need some further tweaking...

many thanks to you for your helpful help Fuzzyselect
Find all posts by this user
Quote this message in a reply
Mar 6, 2014, 16:45 (This post was last modified: Mar 6, 2014 16:51 by mygost.)
Post: #15
RE: how to use the smudge tool in command line or script ?
(Mar 6, 2014 16:19)ofnuts Wrote:  I think you should use the resynthesizer instead (>Filters>Enhance>Heal selection)... not much harder to program:
Code:
pdb.gimp_image_select_rectangle(image,CHANNEL_OP_REPLACE, x, y, width, height)
pdb.python_fu_heal_selection(image,image.layers[0], samplingRadiusParam, directionParam, orderParam)

where the "*param" values can be tested using the interactive version (but likely 0,0 for direction and order).

yes you are right, even if manual smudge give me good results; healing tool seems more appropriate to my purpose;

i'll play a bit with that too...
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Problems with a bat script :( ThaUnknown_ 1 323 Mar 26, 2018 21:14
Last Post: paynekj
  Script-fu ordered file list vnicent 1 169 Mar 19, 2018 17:33
Last Post: paynekj
  script-fu argument/parameter formats dhugg 2 273 Mar 13, 2018 00:50
Last Post: dhugg
  Request for script chlebna 1 450 Sep 13, 2017 09:35
Last Post: ythgilb
  Request for script - Guillotine + Watermark sunslick 1 503 Sep 4, 2017 08:51
Last Post: ythgilb

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS