| Welcome, Guest |
You have to register before you can post on our site.
|
| Forum Statistics |
» Members: 4,991
» Latest member: sebuschi
» Forum threads: 7,731
» Forum posts: 42,025
Full Statistics
|
|
|
| help with running an scm script as batch from bash |
|
Posted by: DanielMalaga - 1 hour ago - Forum: Scripting questions
- No Replies
|
 |
Hello,
with Gimp 2.8 I have an scm script (I found somewhere) that runs perfect on one image when called from the menu within gimp. Now I'd like to run it for a whole directory and wrote a bash script for this.
It works in general, but when running the script on a single image within the Gimp, it creates a group with two layers and places this group above the original image layer. But when running it as a batch with my bash script, the original image layer is inserted within the new group.
Neither grok nor chat gpt could help me successfully :-)
Can you hint me what to change, so that the original image layer stays as a separate layer outside (below) the new layer-group?
(B.t.w., I have literally no idea of Gimp scripting, am just capable to use and adapt a little scripts I find somewhere :-) )
This is my bash script:
Code:
#!/bin/bash
INPUT_DIR="..."
OUTPUT_SUFFIX=".xcf"
BLUR=15
VISIBLE="FALSE"
for file in "$INPUT_DIR"/*.{jpg,png,tif,bmp}; do
if [ -f "$file" ]; then
output_file="${file%.*}${OUTPUT_SUFFIX}"
gimp -i -b "
(let*
(
(filename \"$file\")
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
;; Bottom layer = original image
(layer-info (gimp-image-get-layers image))
(drawable (vector-ref (cadr layer-info) 0))
;; Extract name
(fname (car (reverse (strbreakup filename \"/\"))))
(basename (car (strbreakup fname \".\")))
)
;; Rename to match GUI
(gimp-item-set-name drawable basename)
;; select this layer before FS script
(gimp-image-set-active-layer image drawable)
;; Run FS
(script-fu-hk-frequency-separation image drawable $BLUR $VISIBLE)
;; Save
(gimp-xcf-save RUN-NONINTERACTIVE image drawable \"$output_file\" \"$output_file\")
(gimp-image-delete image)
)
" -b '(gimp-quit 0)'
echo "Processed: $file -> $output_file"
fi
done
This is the scm script:
Code:
; This plugin was tested with Gimp 2.8.3
; This plugin will not work for Gimp 2.6.x because of the unknown layer group
;
; frequency-separartion.scm
; seperates a layer or the whole visible into a
; layer group with high- and low frequency parts
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
(define LList '())
(define (makelist E) (list E))
(define (isempty L) (null? L))
(define (add E L) (cons E L))
(define (Ith i L)
(if (= i 1)
(car L)
(Ith (- i 1) (cdr L))))
(define (fs-set-layers-visible inImage)
(let*
(
(num-layers (length LList))
(theLayer 0)
)
(while (> num-layers 0)
(set! theLayer (Ith num-layers LList))
(gimp-drawable-set-visible theLayer TRUE)
(set! num-layers (- num-layers 1))
)
; (gimp-displays-flush)
(set! LList (list))
)
)
(define (fs-set-layers-invisible inImage inLayer)
(let*
(
(layers (gimp-image-get-layers inImage))
(num-layers (car layers))
(layer-array (cadr layers))
(theLayer 0)
)
(while (> num-layers 0)
(set! num-layers (- num-layers 1))
(set! theLayer (vector-ref layer-array num-layers))
(if (= (car (gimp-drawable-get-visible theLayer) ) TRUE)
(if (<> theLayer inLayer)
(begin
(gimp-drawable-set-visible theLayer FALSE)
(set! LList (cons theLayer LList))
)
)
)
)
; (gimp-displays-flush)
)
)
(define (script-fu-hk-frequency-separation image layer blur visible)
(let*
(
; test, whether seperating a layer group
(isgroup (car (gimp-item-is-group layer)))
; get parent, maybe layer group
(parent (car (gimp-item-get-parent layer)))
; get layername
(layername (car (gimp-item-get-name layer)))
; gets position of layer
(position (car (gimp-image-get-item-position image layer)))
; creates layergroup
(fs-layergroup (car (gimp-layer-group-new image)))
; variables
(helplayer 0)
(lowlayer 0)
(highlayer 0)
(forceVisible 0)
(viewmode 0)
(opacity 0)
)
; FALSE=freqsep just the layer
; TRUE=freqsep from new visible
(if (= visible FALSE)
(begin
(if (= isgroup 1)
(begin
(set! forceVisible 1)
)
(begin
(set! forceVisible 0)
)
)
)
(begin
(set! forceVisible 1)
)
)
(gimp-image-undo-group-start image)
(if (= forceVisible 0)
(begin
(fs-set-layers-invisible image layer)
)
)
;rename layergroup
(gimp-item-set-name fs-layergroup "frequency separation")
;add layergroup as first to the image layer-stack
(gimp-image-insert-layer image fs-layergroup 0 0)
; 0=freqsep just the layer
; 1=freqsep from new visible
(if (= forceVisible 0)
(begin
(set! viewmode (car (gimp-layer-get-mode layer)))
(set! opacity (car (gimp-layer-get-opacity layer)))
(gimp-image-reorder-item image layer fs-layergroup -1)
(gimp-layer-set-mode layer NORMAL-MODE)
(gimp-layer-set-opacity layer 100)
(set! helplayer (car (gimp-layer-copy layer 1)))
(set! lowlayer (car (gimp-layer-copy layer 1)))
(gimp-drawable-set-name helplayer (string-append "help-" layername))
(gimp-drawable-set-name lowlayer (string-append "low-" layername))
)
(begin
(set! helplayer (car (gimp-layer-new-from-visible image image "helplayer")))
(set! lowlayer (car (gimp-layer-new-from-visible image image "low")))
)
)
; adding layers to layergroup
(gimp-image-insert-layer image helplayer fs-layergroup -1)
(gimp-image-insert-layer image lowlayer fs-layergroup -1)
; despeckle the low frequency layer
(plug-in-gauss 1 image lowlayer blur blur 1)
; setting layer mode to get the high frequency layer
(gimp-layer-set-mode lowlayer GRAIN-EXTRACT-MODE)
; getting the high frequency layer. that works, because the lauergroup is topmost
(set! highlayer (car (gimp-layer-new-from-visible image image (string-append "high-" layername))))
; add it it to the layergroup
(gimp-image-insert-layer image highlayer fs-layergroup -1)
; remove the helping layer
(gimp-image-remove-layer image helplayer)
; make the low frequency layer normal
(gimp-layer-set-mode lowlayer NORMAL-MODE)
; make the high frequency layer grain-merge, so the result is the image
(gimp-layer-set-mode highlayer GRAIN-MERGE-MODE)
; put the layergroup just above the layer, that was selected
(gimp-image-reorder-item image fs-layergroup parent position)
(if (= forceVisible 0)
(begin
; restore viewmode and opacity, now for the whole layergroup.
(gimp-layer-set-mode fs-layergroup viewmode)
(gimp-layer-set-opacity fs-layergroup opacity)
(fs-set-layers-visible image)
)
)
(gimp-image-set-active-layer image lowlayer)
(gimp-displays-flush)
(gimp-image-undo-group-end image)
)
)
(script-fu-register "script-fu-hk-frequency-separation"
"Frequency separation..."
"frequency-separation.scm
divides layer in high and low frequencies"
"H.Kuhse"
"H.Kuhse"
"2013-01-04"
"*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Layer" 0
SF-ADJUSTMENT _"Blur:" '(15 1 50 1 1 0 0)
SF-TOGGLE _"from visible (instead selected layer)" 1
)
(script-fu-menu-register
"script-fu-hk-frequency-separation"
"<Image>/Filters"
)
|
|
|
| Problems with AppImages. |
|
Posted by: teapot - 12-08-2025, 07:01 PM - Forum: Installation and usage
- Replies (1)
|
 |
From https://download.gimp.org/gimp/v3.0/linux/
I find these AppImages work fine here:
GIMP-3.0.0-aarch64.AppImage
GIMP-3.0.2-aarch64.AppImage
GIMP-3.0.4-aarch64.AppImage
But these two later ones suffer the same problems:
GIMP-3.0.6-aarch64.AppImage
GIMP-3.2.0-RC1-aarch64.AppImage
When running 3.0.6, the first error printed seems the key one:
(gimp:12345): Gtk-CRITICAL **: 12:34:56.789:
_gtk_css_provider_load_named:
assertion '!g_str_equal (name, DEFAULT_THEME_NAME)' failed
It's repeated often along with lots of subsequent errors. GIMP's main window appears, but the "welcome" window is small, square, and empty. It does not respond to events so I can't close it. Selecting File -> New in the main window has another small, square, empty window appear, like the welcome one, so I can't enter the width, height, etc., to create an image.
I assume some change has happened in how the AppImage has been built so 3.0.4 is happy here, but 3.0.6 isn't. I'm running each from the same shell window on the same machine, etc., so the system around the AppImage is the same.
Searching found a similar problem with an AppImage for Dolphin which the developers fixed, although the problem wasn't what they first thought. Perhaps that's useful to those who understand how AppImages are built. https://github.com/pkgforge-dev/Dolphin-.../issues/20
Is anyone here running 3.0.4 and 3.0.6 AppImages from https://download.gimp.org/gimp/v3.0/linux/ ? Do you suffer the same, or do they work for you?
Any clues on how to sort this?
|
|
|
| Problem posting an update to my plugin |
|
Posted by: Scallact - 12-07-2025, 05:46 PM - Forum: Gimp-Forum.net
- Replies (2)
|
 |
I tried to post a new thread for my updated pl_stroke_arrows plugin, and was granted the "Your are in violation with the forum's rules" message, with a link to said rules.
I don't get what part of my message did upset the forum filter, my post was similar to the previous update.
Any idea what could be wrong?
|
|
|
| Setting a default directory to save files |
|
Posted by: Ofnuts - 12-07-2025, 05:30 PM - Forum: Tutorials and tips
- No Replies
|
 |
You will have noticed that Gimp is hell-bent into saving everything by default in your Documents folder. It's no completely Gimp faults, it is the behavior of the GTK file dialog thayt Gimp uses.
The simple but incomplete solution is to add your favorite folder(s) to the Bookmarks panel on the left.
But you can also make Gimp use any directory by making it think it is your Documents folder.
- The FreeDesktop standard defines several directories: DESKTOP, DOWNLOAD, TEMPLATES, PUBLICSHARE, DOCUMENTS, MUSIC, PICTURES, VIDEOS
- A configuration file called user-dirs.dirs can be used to define what actual directory is used for these symbolic directories. This is typically used to give language-dependent names.
- user-dirs.dirs is normally in ~/.config but you can tell the desktop code to use a different one by setting XDG_CONFIG_HOME environment variable to a directory that contains another version of user-dirs.dirs
- You update the file with the xdg-user-dirs-update command, and you can check it use the xdg-user-dir command. These two commands will of course check the XDG_CONFIG_HOME environment variable.
So, all that is needed is to prepare a user-dirs.dirs pointing to the required directory, and set the XDG_CONFIG_HOME environment variable to point to the alternate user-dirs.dirs directory in a script before calling Gimp.
So for instance, setting your destination directory to ~/tmp:
Do once:
Code:
export XDG_CONFIG_HOME=~/tmp/ # directory for user-dirs file, and your Gimp files
xdg-user-dirs-update --set DOCUMENTS ~/tmp # Creates/updates the user-dirs file
Before calling Gimp (so create/modify script):
Code:
export XDG_CONFIG_HOME=~/tmp/ # tell FreeDesktop where to look for directories definition
gimp # start Gimp (can also be "exec gimp" to get rid of one level of shell)
The exemple above keeps the user-dirs.dir file and the Gimp files in the same directory but using different directories is left as an exercise for the reader.
If any Windows or OSX users are reading this, I wonder if this applies in other OS as well. If you are missing the xdg-user-dirs-update command, user-dirs.dirs is a plain text file and it looks like this:
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
XDG_DOCUMENTS_DIR="$HOME/tmp"
|
|
|
| Fix low resolution images |
|
Posted by: JoeCool59 - 12-05-2025, 06:33 PM - Forum: General questions
- Replies (5)
|
 |
I'm a casual GIMP user. I have some old digital images shot or digitized in low resolution (pixelated). The one I'm currently working on was a jpeg from around 1990. I opened it and screenshot it and now it's a 600ppi png, but the image retains all the compression artifacts that are left over from its original life as a 70ppi jpeg. Is depixelating it an art? I recognize that GIMP is incapable of knowing what information should be in the image. I'm eager to learn new things in GIMP.
|
|
|
| GIMP 3 script-fu not loading and run with error when Loaded through Console |
|
Posted by: markhahn2000 - 12-04-2025, 09:06 PM - Forum: Scripting questions
- Replies (1)
|
 |
new to v3 and having scripting issues.
My test case is a published "hello World"script. (https://testing.developer.gimp.org/resou...script-fu/)
On MacOS I have given GIMP full access in system settings. I have placed this .scm in a subdirectory with the same name as the executable .scm file. In Folders, this script directory is the first listed.
It does not show up when I restart GIMP.
I've read that I can load it in the Console, and when I do this, I get the error:
"Error: eval: unbound variable: (/Users/mark/GIMP_scriptfu/mh_hello_world3/mh_hello_world.scm : 35) [] "
On line 35 in the script, it holds the copyright year. How is this causing this script to error out?
I have tried different example scripts and am getting similar errors.
I am new to this. Thanks for any help!
Code:
#!/usr/bin/env gimp-script-fu-interpreter-3.0
(define (script-fu-zemarmot-hello-world
image
drawables
font
compute-size
size
text)
(script-fu-use-v3)
(let* ((layer (gimp-text-layer-new image text font size UNIT-PIXEL)))
(gimp-image-undo-group-start image)
(gimp-image-insert-layer image layer -1 0)
(if (= compute-size TRUE)
(let* ((image-width (gimp-image-get-width image))
(layer-width (gimp-drawable-get-width layer)))
(begin
(set! size (* size (/ image-width layer-width)))
(gimp-text-layer-set-font-size layer size UNIT-PIXEL)
)
)
)
(gimp-image-undo-group-end image)
)
)
(script-fu-register-filter "script-fu-zemarmot-hello-world"
"Script-Fu v3 Hello World"
"Official Hello World Tutorial in Script-Fu v3"
"Jehan"
"Jehan, Zemarmot project"
"2025"
"*"
SF-ONE-OR-MORE-DRAWABLE
SF-FONT "Font" "Sans-serif"
SF-TOGGLE "Compute Ideal Size" #f
SF-ADJUSTMENT "Font size (pixels)" '(20 1 1000 1 10 0 1)
SF-STRING "Text" "Hello World!"
)
(script-fu-menu-register "script-fu-zemarmot-hello-world" "<Image>/Hello W_orlds")
|
|
|
|