g'mic for batching

Moderator: Kathy_9

LeviFiction
Advisor
Posts: 6774
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

g'mic for batching

Post by LeviFiction »

This is less of an actual full script as it is a tutorial on one possible way to execute g'mic filters reliably in script and on images using batch processing.

Quick background - G'Mic is a research tool and image processing pipeline that has several different options to work with. The most popular is the built-in option with GIMP, followed close-behind by the Photoshop plugin that works with products like Paint Shop Pro and others. The plugin opens a separate program that executes commands on your image and then sends the fully processed image back to PSP. The big problem, however, is that as far as I know it doesn't properly support recording what you did in script form and sending it back to the plugin to get a repeat effect via script recording. And it doesn't properly run in silent mode.

That's where g'mic for batching comes in. This makes use of the g'mic cli version to execute the same effect over multiple images. It has its flaws and weaknesses but once you're set up, you can play with what you want it to do in the g'mic plugin, and copy the commands for use in the "g'mic for batching" script.

Assumptions made in this tutorial: 1) You already have the G'Mic plugin installed. And 2 - you've hopefully used commandline before. Because I am not going to give the best instructions on this.

Video Demo

[Let's get started]

Let's get started, first you need to download G'Mic CLI zip file. And you need to unzip it somewhere you can find easily. I personally put it in my C:\ directory (never a good idea), but you might consider putting it in your user directory. C:\Users\YourUserName\

To download go here - https://gmic.eu/download.html
Look for the section titled "G'MIC for Windows - Other interfaces" and click on the "stable" link underneath "Command-line interface (CLI):". This downloads a zip file with the gmic CLI.

Again unzip it somewhere and give the resulting folder an easy name like "gmic". it keeps things short and easy to type.

Next open up a powershell or commandline window and navigate to the folder where the gmic.exe program is located. If you've never used the commandline it's pretty easy. Just use the "cd" command followed by either the full path or the folder name you want to go to. For example let's say I put the gmic folder in my user folder. I would simply type (without quotation marks) "C:\users\YourUserName\gmic\"

Then you need to run the following command "gmic update" or if you're in powershell ".\gmic.exe update"

This makes sure that gmic has the latest information on all of the commands it can run. We're almost done with initial setup. The last thing to do is download the gmic for batching script and tell it where to find the gmic cli program.

[The script part]
Download the script attached to this post (it's zipped up so you will have to unzip it) and put it into the Scripts-Trusted folder for your version of PSP. Then open it in Notepad and look for this line near the top of the script.

Code: Select all

#####################################
gmic = "C:\\Users\\YourUsername\\gmic\\gmic.exe"
#####################################
I've made it simultaneously easier to spot and harder to look at by adding a ton of unnecessary hash signs around it.

Update the path to point to the same location as your gmic.exe file. Really quick you'll notice that we have to put '\\' between folder names because the '\' symbol has special meaning in Python (the scripting language for PSP). So make sure when entering the location of your gmic cli tool that you're using double slashes instead of single slashes.

Now there is only one last thing to do. Get the gmic command code from the G'Mic plugin so we can duplicate the effect over and over again. Hopefully without fail.

Open PSP and run the g'mic plugin on an iamge. Find an effect you want to use, set the settings the way you like, and then click on the copy command button in the top right-corner. You can see it highlighted here
copy-gmic-command.png
You'll get text copied to your clipboard with the command needed to duplicate the effect you've just made. Here's an example of the bokeh command.

Code: Select all

fx_bokeh 3,8,0,30,8,4,0.3,0.2,210,210,80,160,0.7,30,20,20,1,2,170,130,20,110,0.15,0,50,50
Go back to your script and find this line

Code: Select all

# run gmic with command
    execute_gmic(filename,"YourCommandHere")
Replace the text between the quotes "YourCommandHere" with the command you copied from the gmic plugin. If you want to perform multiple commands in one go simply put a space after your first command and copy the next command after it still between the quotes. You can put several commands together like that in one line.

Save the script and give it a test run. If all goes well it should run, a commandline box will open showing the progress, and then the result should open as a new layer at the top of your layers palette.

If it works you can now use this script to apply a very specific set of gmic commands to get a specific look quickly and easily. Well...semi quickly. SSD hard drives will probably run faster than it does on my mechanical one. It also doesn't always respect transparency. The Bokeh command above, for example, will ignore transparency resulting in a white background. I need to learn more to see if there is anything I can do about that in a future update.
You do not have the required permissions to view the files attached to this post.