Gimp-Forum.net
Mass blur images via Python-Fu - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: Mass blur images via Python-Fu (/Thread-Mass-blur-images-via-Python-Fu)



Mass blur images via Python-Fu - everetttt - 08-14-2023

Hello, I am wanting to streamline a process to blur every image (all jpegs) in a directory that I have, as doing it all manually would be extremely time consuming. I have found many people using Python-Fu, and so I believe to add my scrip to GIMP I would open any file, Filters -> Python-Fu -> Console and enter code, of which I have the following

Code:
from gimpfu import*

def plugin_blur_post(timg, tdrawable):


   new_layer = pdb.gimp_layer_copy(tdrawable, 0)
   timg.add_layer (new_layer, 0)
    
   pdb.plug_in_gauss_iir(timg, new_layer, 25, True,True)
   gimp.pdb.file_jpeg_save(timg, new_layer, (car (gimp-image-get-filename)) + "_blurred.jpg", "raw_filename", 0.85, 0, 0, 1, "", 3, 0, 0, 0)


register(
       "python_fu_blur",
       "blur-posterize",
       "*",
       "*",
       "*",
       "*",
       "<Image>/Tools/blur-posterize...",
       "*",
       [],
       [],
       plugin_blur_post)

main()
This, I hope, adds a gaussian blur with both X and Y values of 25, then saves as a new jpeg, with the name being currentName_blurred.jpg
Unfortunately, this just crashes the console when I copy paste it all in.

Finally, as I want to apply this to all files in my directory (including images within folders), I believe I have to run a similar command as found here. So, I believe I would navigate to the folder and run the command
Code:
gimp -i -b '(python_fu_blur "*.jpg" 5.0 0.5 0)' -b '(gimp-quit 0)'
As the code doesn't yet compile, I can't run the command, but in Windows Powershell gimp is not even recognized as a name. I've tried both this and this but neither allow me to call gimp.

I realize this is effectively three separate errors in one post and I do apologize for that. Thank you for any help offered, I really do appreciate it.


RE: Mass blur images via Python-Fu - rich2005 - 08-14-2023

I am sure someone will be along to discuss getting your plugin working, 

However, there is a Gimp batch plugin BIMP which will blur / rename / change format if required. https://alessandrofrancesconi.it/projects/bimp/

The setup might look like this: https://i.imgur.com/qLJW3gz.jpg


RE: Mass blur images via Python-Fu - Ofnuts - 08-14-2023

(08-14-2023, 05:26 PM)everetttt Wrote: Hello, I am wanting to streamline a process to blur every image (all jpegs) in a directory that I have, as doing it all manually would be extremely time consuming. I have found many people using Python-Fu, and so I believe to add my scrip to GIMP I would open any file, Filters -> Python-Fu -> Console and enter code, of which I have the following

Code:
from gimpfu import*

def plugin_blur_post(timg, tdrawable):


   new_layer = pdb.gimp_layer_copy(tdrawable, 0)
   timg.add_layer (new_layer, 0)
    
   pdb.plug_in_gauss_iir(timg, new_layer, 25, True,True)
   gimp.pdb.file_jpeg_save(timg, new_layer, (car (gimp-image-get-filename)) + "_blurred.jpg", "raw_filename", 0.85, 0, 0, 1, "", 3, 0, 0, 0)


register(
       "python_fu_blur",
       "blur-posterize",
       "*",
       "*",
       "*",
       "*",
       "<Image>/Tools/blur-posterize...",
       "*",
       [],
       [],
       plugin_blur_post)

main()
This, I hope, adds a gaussian blur with both X and Y values of 25, then saves as a new jpeg, with the name being currentName_blurred.jpg
Unfortunately, this just crashes the console when I copy paste it all in.

Finally, as I want to apply this to all files in my directory (including images within folders), I believe I have to run a similar command as found here. So, I believe I would navigate to the folder and run the command
Code:
gimp -i -b '(python_fu_blur "*.jpg" 5.0 0.5 0)' -b '(gimp-quit 0)'
As the code doesn't yet compile, I can't run the command, but in Windows Powershell gimp is not even recognized as a name. I've tried both this and this but neither allow me to call gimp.

I realize this is effectively three separate errors in one post and I do apologize for that. Thank you for any help offered, I really do appreciate it.

No need for a plugin if you run batch, see this.

Now, as usual, for simple batch ops, ImageMagick is usually a much better choice, and as expected it has a blur operation.