batch resize images with gimp - gimp

I want to resize every jpg in a directory.
This is the gimp script I've found. Looks sensible to me.
(define (batch-resize pattern)
(let*
((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* (
(filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-active-drawable image)))
(cur-width (car (gimp-image-width image)))
(cur-height (car (gimp-image-height image)))
(width (* 0.25 cur-width))
(height (* 0.25 cur-height))
)
(gimp-message filename)
(gimp-image-scale-full image width height INTERPOLATION-CUBIC)
(let
((nfilename (string-append "thumb_" filename)))
(gimp-file-save RUN-NONINTERACTIVE image drawable nfilename nfilename)
)
(gimp-image-delete image)
)
(set! filelist (cdr filelist))
)
)
)
I saved this as C:\Users\rwb\.gimp-2.8\scripts\batch-resize.scm and then call
"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" -i -b '(batch-resize "*.JPG")' -b '(gimp-quit 0)'
The ouptut is
>"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" -i -b '(batch-resize "*.JPG")' -b '(gimp-quit 0)'
(gimp-console-2.8.exe:7568): LibGimpBase-WARNING **: gimp-console-2.8.exe: gimp_wire_read(): error
batch command executed successfully
batch command executed successfully
At which point it just hangs.
I was expecting the (gimp-message filename) to print the filenames but nothing!
I really have no idea what is going on here! Can you offer any suggestions? Even printing the filenames would be a start.

The problem arises from the way you are quoting the command-line. This should work:
"c:\Program Files\GIMP 2\bin\gimp-console-2.10.exe" -b "(batch-resize \"*.JPG\")" -b "(gimp-quit 0)"
Note that it is updated for GIMP 2.10. Additionally, user script files now live in:
c:\Users\rwb\AppData\Roaming\GIMP\2.10\scripts
And finally, the code block in your question was formatted with the final parenthesis outside the block, which made it easy to miss. I've updated that.

Related

invoke GIMP script-fu from command line

I can't get any GIMP Fu script to work (using Gimp 2.10.32 (Revision 1) on Windows 10 Pro 21H2 19044.1826).
Consider this minimal script. It is supposed to read a file and write it out again under a different name, without applying any modifications: (Source: https://superuser.com/a/1558320/1130040)
(define
(mytest in_filename out_filename)
(let* (
(image (car (gimp-file-load RUN-NONINTERACTIVE in_filename in_filename)))
(drawable (car (gimp-image-get-active-layer image))))
(gimp-file-save RUN-NONINTERACTIVE image drawable out_filename out_filename)
(gimp-image-delete image)
)
)
While testing, I also added a 'script-fu-register' block that let's me check in GIMP's procedure browser that the script was detected and loaded without errors. Thus, also the location of the script is correct, as well as the set script paths under options.
(script-fu-register "mytest"
""
_"Test"
""
""
"2022/07/16"
""
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
)
To start the script, 'cd' to the directory (which is %userprofile%\pictures) containing the source image 'p.jpeg' and invoke:
"C:\Program Files\GIMP 2\bin\gimp-2.10.exe" -idf -b '(mytest p.jpeg p1.jpeg)' -b '(gimp-quit 0)' --verbose
I am expecting 'p1.jpeg' being an exact copy of 'p.jpeg' to be written out in the same directory.
What happens: A protocol window opens, containing:
(...)
Starting extension: 'extension-script-fu'
No batch interpreter specified, using the default 'plug-in-script-fu-eval'.
batch command executed successfully
batch command executed successfully
Then it stays open. No error messages. But no output file either.
If I missspell the function name 'mytest' or pass a non-existing file name as the first argument (something.jpeg), I won't receive an error message.
I got rid of the message 'No batch interpreter specified' by adding --batch-interpreter plug-in-script-fu-eval.
I tried:
reinstalled Gimp
alternativly on a clean Windows 11 Pro 21H2 22000.795
different directories for the source/dest. image file
different image formats (.png, .jpeg) and files
command window as elevated admin and as normal user
a different script (https://opensource.com/article/21/1/gimp-scripting)
with and without the block 'script-fu-register'
file parameter with and without quotation marks, full path
executing all commands from the command line using -b '(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE p.jpeg p.jpeg)))(drawable (car (gimp-image-get-active-layer image))))(gimp-file-save RUN-NONINTERACTIVE image drawable p1.jpeg p1.jpeg)(gimp-image-delete image))'
Finally I got it working using the following command line syntax on Windows:
"C:\Program Files\GIMP 2\bin\gimp-2.10.exe" -idf -b "(mytest \"p.jpeg\" \"p1.jpeg\")" -b "(gimp-quit 0)"
Double quotes " arround each -b command
Escaped double quotes \" before and after each parameter.

How to run datalog in Z3 using commad line

I try to run datalog file (test.dl, from http://rise4fun.com/Z3/tutorialcontent/fixedpoints#h21) as following in Z3 (version:4.3.2).
(set-option :fixedpoint.engine datalog)
(define-sort s () (_ BitVec 3))
(declare-rel edge (s s))
(declare-rel path (s s))
(declare-var a s)
(declare-var b s)
(declare-var c s)
(rule (=> (edge a b) (path a b)))
(rule (=> (and (path a b) (path b c)) (path a c)))
(rule (edge #b001 #b010))
(rule (edge #b001 #b011))
(rule (edge #b010 #b100))
(query (path #b001 #b100))
(query (path #b011 #b100))
(query (path #b001 b)
:print-answer true)
Use the command z3 test.dl, but there is erorr msg:
Can someone help how to run the datalog file?
Thanks.
The input format for this file is SMT2, not Datalog. Even though you want to run the Datalog engine, the file isn't in Datalog format and so the parser gives you the error that you see.
Running Z3 with the command z3 -smt2 test.dl was successful, as this forces Z3 to use the SMT2 parser and not the Datalog one. Alternatively, renaming the file to test.smt2 and running z3 test.smt2 works.
Both commands produced what I believe is the expected output
sat
unsat
sat
(or (= (:var 0) #b011) (= (:var 0) #b010) (= (:var 0) #b100))

z3 # command line behaving differently than online

the (rather small) query that I have here:
http://rise4fun.com/Z3/W4sf
works just fine on the website (above) but hangs
when I run it on my mac, with
z3 -in
followed by pasting in the exact text above, which is:
(declare-const x Real)
(assert (not (= 0.0 x)))
(assert (not (< 0.0 (* x x))))
(check-sat)
Any ideas? I thought it might be that I have an old version but its 4.3.2
rjhala#borscht ~/bin [130]> z3 -help
Z3 [version 4.3.2 - 64 bit - build hashcode 5b5a474b5443].
Am I missing some parameters? Or any other suggestions? Many thanks!
Ranjit.
It also seemed not to return for me using that, but it seems to work as:
z3 -in -smt2
Followed by pasting the query, so I think it may need the -smt2 parameter. I tried it on Windows with 4.3.3 (I thought I had 4.3.2, but it seems I updated from the latest unstable branch):
C:\Users\tjohnson>z3 -in -smt2
(declare-const x Real)
(assert (not (= 0.0 x)))
(assert (not (< 0.0 (* x x))))
(check-sat)
unsat
It also worked for me by pasting the query into test.smt and running:
C:\Users\tjohnson>z3 -smt2 test.smt
unsat

Emacs flymake on Mac Yosemite

Flymake in emacs was properly working until update to Yosemite. But now it's complaining:
Flymake: Failed to launch syntax check process 'pychecker' with args (<filename>_flymake.py): Searching for program: no such file or directory, pychecker. Flymake will be switched OFF.
where <filename> is the name of the file in the opened buffer.
Here's my flymake config:
(add-to-list 'load-path "~/.emacs.d/")
;; Setup for Flymake code checking.
(require 'flymake)
(load-library "flymake-cursor")
;; Script that flymake uses to check code. This script must be
;; present in the system path.
(setq pycodechecker "pychecker")
(when (load "flymake" t)
(defun flymake-pycodecheck-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list pycodechecker (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pycodecheck-init)))
(add-hook 'python-mode-hook 'flymake-mode)
here's /usr/local/bin/pychecker:
#! /bin/sh
pyflakes "$1"
pep8 --repeat "$1" --max-line-length=80 --ignore=E123,E133,E226,E501
true
here's $PATH:
/Users/<user>/Envs/<venv>/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/texbin
where <user> is my user name and <venv> is the currently active virtual-env.
pychecker works properly if run from the shell.
I start emacs from shell by typing emacsgui (alias emacsgui='open -a emacs'), usually with the venv activated. I also tried opening emacs without any venv activated but the problem still occur. What is the problem?
I solved by adding this to my .emacs file:
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (replace-regexp-in-string
"[ \t\n]*$"
""
(shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when (and window-system (eq system-type 'darwin))
;; When started from Emacs.app or similar, ensure $PATH
;; is the same the user would see in Terminal.app
(set-exec-path-from-shell-PATH))

I can't send some command line parameters via Autohotkey to VLC

I can't figure out how to get my audio extractor script working via commandline arguments on ahk. I know the command line argument is correct, as I'm able to get it working through a batch file, but I keep getting the error below. I think I'm probably doing something wrong syntactically but I just can't figure out what.
I'd really appreciate any help. Thanks.
Error: the following variable name contains an illegal character"
channels=2,samplerate=44100}:standard{access="file",mux=dummy,dst="%A_LoopField%.mp3"}
Code:
fileselectfile, File_Name, M3
SplitPath, File_Name, name
Loop, parse, name, `n
if a_index = 2
{
msgbox, %A_LoopField%
Run, "C:\Program Files\VideoLAN\VLC\vlc.exe" "-I dummy -v %File_Name% :sout=#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100}:standard{access="file",mux=dummy,dst="%A_LoopField%.mp3"}"
}
Here is the original batch code if you're curious about the audio extraction function I was talking about
#ECHO OFF
REM Loop through files (Recurse subfolders)
REM Syntax
REM FOR /R [[drive:]path] %%parameter IN (set) DO command
REM
REM Key
REM drive:path : The folder tree where the files are located.
REM
REM set : A set of one or more files. Wildcards must be used.
REM If (set) is a period character (.) then FOR will
REM loop through every folder.
REM
REM command : The command(s) to carry out, including any
REM command-line parameters.
REM
REM %%parameter : A replaceable parameter:
REM in a batch file use %%G (on the command line %G)
FOR /R %%G IN (*.mp3) DO (CALL :SUB_VLC "%%G")
FOR /R %%G IN (*.mp3.mp*) DO (CALL :SUB_RENAME "%%G")
GOTO :eof
:SUB_VLC
SET _firstbit=%1
SET _qt="
CALL SET _newnm=%%_firstbit:%_qt%=%%
SET _commanm=%_newnm:,=_COMMA_%
REM echo %_commanm%
ECHO Transcoding %1
REM Here's where the actual transcoding/conversion happens. The next line
REM fires off a command to VLC.exe with the relevant arguments:
CALL "C:\Program Files\VideoLAN\VLC\vlc" -I dummy -v %1 :sout=#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100}:standard{access="file",mux=dummy,dst="%_commanm%.mp3"} vlc://quit
REM Having no SLEEP-esque command, we have to trick DOS/Windows into pausing
REM for a bit between encode ops - To give the host OS a chance to do what it
REM needs to - Via clever use of the PING utility:
REM (Thanks to http://www.computing.net/answers/programming/dos-command-for-wait-5-seconds/11192.html for the tip! :-)
PING -n 1 -w 10000 1.1.1.1 > NUL
GOTO :eof
:SUB_RENAME
SET _origfnm=%1
SET _endbit=%_origfnm:*.mp3=%
CALL SET _newfilenm=%%_origfnm:.mp3%_endbit%=.mp3%%
SET _newfilenm=%_newfilenm:_COMMA_=,%
COPY %1 %_newfilenm%
GOTO :eof
:eof
REM My own little addition to prevent the batch window from "vanishing" without
REM trace at the end of execution, as if a critical error had occurred.
PAUSE
Have you tried without the SplitPath, File_Name, name? I got rid of the error like this, but I don't know if it produces the result you want in the end.
I found the answer. I was making syntatical errors I just didn't have the knowledge to fix myself. The new RUN statement works perfectly.
Here is the newly revised script
fileselectfile, File_Name, M3
SplitPath, File_Name, name, dir, ext, name_no_ext, drive
StringReplace, File_Name, File_Name,`n, \
Loop, parse, name, `n
{if a_index = 2
msgbox, %A_LoopField%
Run % "C:\Program Files\VideoLAN\VLC\vlc.exe -I dummy -v """ File_Name """ :sout=#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100}:standard{access=""file"",mux=dummy,dst=""" A_LoopField ".mp3""} "
}

Resources