Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Blur, change mode, save as
#8
(11-21-2022, 11:42 PM)Ofnuts Wrote: Plenty of problems...

Ai-ai!  Wink Lets see how far I get.

(11-21-2022, 11:42 PM)Ofnuts Wrote:
  • SyntaxError: Non-ASCII character '\xc2' in file Blur.py on line 4, but no encoding declared;: Many of your lines start with "non-breaking spaces" (0xA0, or 0xC2A0 once encoded in UTF8), so likely you are using a word processor to write your code  and it tries to "help" by putting non-breaking spaces where you put spaces. Change for a real editor (Notepad++ is free) that won't try to outguess you.

Indeed I started the script in Windows notepad, but soon switched to Notepad++ as it gives better overview.
I fixed the spaces. I used the [TAB] key for the indents, and I went over all hard-returns.
In Notepad++ ofcourse. Language is set to Python.

(11-21-2022, 11:42 PM)Ofnuts Wrote:
  • The last argument of your register() call is tkemmere_blur. This is supposed to be the name of a function, but this function is defined nowhere. I suggest you rename the plugin_main function to tkemmere_blur.

Done! Thanks!

(11-21-2022, 11:42 PM)Ofnuts Wrote:
  • The plugin_main/tkemmere_blur function takes two arguments, an image and a layer (and this is what your real function you take as a minimum). So your register() call should declare these argument, so that Gimp can call your function with the adequate arguments. In the code you copied, the first pair of brackets in register() likely contains a PF_IMAGE and a PF_DRAWABLE line, that should also be present in your register().

The source where I got my 'register()' example from didn't have PF_IMAGE nor a PF_DRAWABLE line. I looked up how to include them but Register() takes the following parameters acciring to help.register in the console: (proc_name, blurb, help, author, copyright, date, label, imagetypes, params, results, function, menu=None, domain=None, on_query=None, on_run=None). I'm not using the last 4. But I don't understand how I declare PF_IMAGE and PF_DRAWABLE in my register().

(11-21-2022, 11:42 PM)Ofnuts Wrote:
  • The code I provided is going to be part of the body of your tkemmere_blur function, and the variabe image in that code is the first parameter (timg) in your function  (so you have to change of of these names)

I adjusted the first parameter in the def tkemmere_blur() into 'image'. And the second to 'layer'.

(11-21-2022, 11:42 PM)Ofnuts Wrote: To debug a python script, see this tutorial:  Debugging python-fu scripts in Windows

Thank you, I ran the code in the Python-fu console. Bit by bit.
  • It crashes at "main()". I don't know the point of this line.
  • It also says rootName should be defined. Should that be a path to a file location?
  • Otherwise no errors.
And the result for now:
Code:
from gimpfu import *

def tkemmere_blur(image, layer):
    print "Hello, world!"
    
register(
    "tkemmere_blur",
    "Blur en 5 tinten maken en dat 5x met verschillende blur",
    "Blur en 5 tinten maken en dat 5x met verschillende blur",
    "tkemmere",
    "tkemmere",
    "21-11-2022",
    "<Image>/Filters/tkemmere blur",
    "RGB*, GRAY*",
    [],
    [],
    tkemmere_blur)    # How to declare image and layer in this register function?
    
main()

def rootName("T:/files") # Should rootName be a path?

for blur in [10,20,30,40]:
    outputFile="%s-%02d.png" % (rootName,blur)    # Possibly a bit more complex than this
    blurImage=image.duplicate()            # Temporary copy
    pdb.gimp_image_undo_disable(blurImage)        # Disable undo
    layer=blurImage.activeLayer
    pdb.plug_in_gauss_iir(blurImage, layer, blur, True,True)
    pdb.gimp_drawable_posterize(layer,5)
    pdb.file_png_save_defaults(image, layer, outputFile, outputFile) # Other calls possible with more options
    gimp.delete(blurImage)                         # Throw away this copy

If I understand correctly, due to the lack of declaring image and layer in the register function, Unfortunately it doesn't yet appear in the Filters menu.

Now I will dive into what @Rich2005 wrote. Not sure whether I manage to respond, it is late now and tomorrow is a day with a full schedule that unfortunately leaves me no Gimp/Py time.

Thanks @Ofnuts!

(11-22-2022, 01:30 PM)rich2005 Wrote:
Quote:A ...Python is reasonably understandable, script-fu akin to Sanskrit...

B ...Try and find some simple examples first, never mind the code... ...get your code between that...

C ...work in a linear mode...

Hi Rich2005,

Thanks to you as well!

A. Yes, I went the Python way now. Not thinking of turning back reading the Sanskrit metaphore!  Confused
B. I got your script running, in the Tools menu, so that will do, to elaborate on!  Smile
C. Your script is written lineair. Copy pasting a couple of lines is no problem of course, but automating it into a loop is of course more fun and elegant.  Wink

I ran the script from the Tools menu and it is working here too! It can't save, a permission thing, I'll look into that later. I really need to sleep now.

Thanks! Forums are great! I'm afraid I can't do much back on this one, but I can mention that on the FileMaker Pro forum I also do help people out.

Will be back.  Smile
Cheers, Thomas.
Reply


Messages In This Thread
Blur, change mode, save as - by tkemmere - 11-21-2022, 09:50 AM
RE: Blur, change mode, save as - by Ofnuts - 11-21-2022, 11:12 AM
RE: Blur, change mode, save as - by tkemmere - 11-21-2022, 12:11 PM
RE: Blur, change mode, save as - by Ofnuts - 11-21-2022, 12:40 PM
RE: Blur, change mode, save as - by tkemmere - 11-21-2022, 10:47 PM
RE: Blur, change mode, save as - by Ofnuts - 11-21-2022, 11:42 PM
RE: Blur, change mode, save as - by rich2005 - 11-22-2022, 01:30 PM
RE: Blur, change mode, save as - by tkemmere - 11-22-2022, 10:49 PM
RE: Blur, change mode, save as - by tkemmere - 11-23-2022, 10:39 PM

Forum Jump: