Post Reply 

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

Mar 5, 2014, 15:31
Post: #16
RE: how to use the smudge tool in command line or script ?
This seems to work:

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)

  logFile = open("C:\\tmp\\logfile.txt", "w")
  logFile.write("File %s loaded OK\n" % infile)
  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
  logFile.write("Saving to %s\n" % outfile)
  pdb.file_jpeg_save(image, drawable, outfile, outfile, "1",0,1,0,"",0,1,0,0)
  print "Saved to %s" % outfile
  logFile.write("Saved to %s\n" % outfile)
  pdb.gimp_image_delete(image)

  logFile.close

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)


# This is the plugin registration function
register(
    "python_fu_smudge_temporary",    
    "Python Smudge",
    "GNU GPL v3 or later.",
    "Ragnar ",
    "Ragnar ",
    "January 2012",
    "Python Smudge...",
    "",
    [
      (PF_DIRNAME,   "directory", "Directory", ""),
    ],  
    [],
    run,
    menu="<Image>/contributed/"
)

main()

I added in the bits to run it interactively, and I had to manually create the "processed" folder.

Kevin
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 16:23
Post: #17
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: #18
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:07 (This post was last modified: Mar 5, 2014 17:08 by paynekj.)
Post: #19
RE: how to use the smudge tool in command line or script ?
(Mar 5, 2014 16:23)mygost Wrote:  guess you run it on linux... hhmmm, guess i'll give up and buy a iMac... pfff

Windows 7 64 bit with GIMP 2.6.7 and GIMP 2.8.2

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.

Kevin
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 17:38 (This post was last modified: Mar 5, 2014 17:43 by paynekj.)
Post: #20
RE: how to use the smudge tool in command line or script ?
(Mar 5, 2014 17:07)paynekj Wrote:  Which may mean that a brush needs to be selected first.

It certainly does. If I insert set the brush before smudging then it works from the command line:

Code:
pdb.gimp_context_set_brush("2. Hardness 050")

If you are using GIMP in French, then I expect the brush name is translated, so you will have to find out the name of the brush you want to use.

The other thing I forgot to say was that I changed the batch file command line to something I know works:

Code:
"C:\Program Files\GIMP 2.8.2\bin\gimp-console-2.8.exe" --verbose -b "(python-fu-smudge-temporary RUN-NONINTERACTIVE \".\")" -b "(gimp-quit 0)" > out.log 2>&1

Kevin
Find all posts by this user
Quote this message in a reply
Mar 5, 2014, 17:43 (This post was last modified: Mar 5, 2014 17:44 by ofnuts.)
Post: #21
RE: how to use the smudge tool in command line or script ?
(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)

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
Mar 5, 2014, 17:57 (This post was last modified: Mar 5, 2014 17:58 by mygost.)
Post: #22
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: #23
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 5, 2014, 18:44
Post: #24
RE: how to use the smudge tool in command line or script ?
Do you still have the -d option on your command line as this tells GIMP not to load brushes (among other things)?
Find all posts by this user
Quote this message in a reply
Mar 6, 2014, 16:01
Post: #25
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:19
Post: #26
RE: how to use the smudge tool in command line or script ?
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).

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
Mar 6, 2014, 16:45 (This post was last modified: Mar 6, 2014 16:51 by mygost.)
Post: #27
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
  Request for script chlebna 1 96 Sep 13, 2017 09:35
Last Post: ythgilb
  Request for script - Guillotine + Watermark sunslick 1 163 Sep 4, 2017 08:51
Last Post: ythgilb
  Script-fu: How to create new, addressable layer using gimp-floating-sel-to-layer Bertholom√§us 2 149 Aug 31, 2017 14:32
Last Post: Bertholomäus
  How to modify this script-fu? Zakary81 1 119 Aug 23, 2017 12:48
Last Post: paynekj
  How to close gimp with batch command? flixe 1 215 Jun 19, 2017 12:29
Last Post: ythgilb

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS