You are not logged in.
This utilizes the Gimp batch system which requires some set up there.
in your .../.gimp-2.x/scripts directory you need to create to files: GimpRotRight.scm and GimpRotLeft.scm
GimpRotRight.scm:
(define (Gimp-Rotate-Right filename)
(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(gimp-image-rotate image 0)
(set! drawable (car (gimp-image-get-active-layer image)))
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
(gimp-image-delete image)))
GimpRotLeft.scm:
(define (Gimp-Rotate-Left filename)
(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(gimp-image-rotate image 2)
(set! drawable (car (gimp-image-get-active-layer image)))
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
(gimp-image-delete image)))
next create your custom actions
Name: GimpRotRight
Description: Gimp Rotate Right
Command: for file in %F; do /bin/sh -c "gimp -i -b '(Gimp-Rotate-Right "\""$file"\"")' -b '(gimp-quit 0)'" ; done
check off Image Files for "Appears if selection contains"
Name: GimpRotLeft
Description: Gimp Rotate Left
Command: for file in %F; do /bin/sh -c "gimp -i -b '(Gimp-Rotate-Left "\""$file"\"")' -b '(gimp-quit 0)'" ; done
check off Image Files for "Appears if selection contains"
It appears rather straight forward.
But I spend 16 hours of research and trail and error to finally get it to work.
It works for single and multiple selection.
I use it to rotate pictures physically (not exif modification), because when doing slide shows using kdenlive it need the pictures rotated physically.
Hope you all find it useful.
Offline
Hello, welcome, and thanks for sharing.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
This is a very usefull ustom action. Thanks for sharing
dropbox.com - 2GB free online storage.
Offline
Another way to do this, if you don't want to keep the files in /home/user/.gimp-2.x/scripts,
create one script anywhere you like and use that script to rotate left, right or 180
gimp-rotate.sh
#!/bin/sh
# Rotate with python-fu
if [ $# -ne 2 ];
then
echo 'Usage: gimp-rotate.sh "file" [right|left|180]'
exit
fi
case "$2" in
right)
OPT=0
;;
left)
OPT=2
;;
180)
OPT=1
;;
*)
echo 'Usage: gimp-rotate.sh "file" [right|left|180]'
exit
;;
esac
gimp -d -i --batch-interpreter=python-fu-eval -b - << EOF
import gimpfu
def rotate(filename):
img = pdb.gimp_file_load(filename, filename)
layer = pdb.gimp_image_merge_visible_layers(img, 1)
pdb.gimp_image_rotate(img, '${OPT}')
pdb.gimp_file_save(img, layer, filename, filename)
pdb.gimp_image_delete(img)
rotate('${1}')
pdb.gimp_quit(1)
EOF
make it executable
chmod 755 gimp-rotate.sh
Commands to use in thunar custom actions (replace /path/to/)
for file in %F; do /path/to/gimp-rotate.sh "$file" right; done
for file in %F; do /path/to/gimp-rotate.sh "$file" left; done
for file in %F; do /path/to/gimp-rotate.sh "$file" 180; done
Compliments from Misko
Last edited by Misko_2083 (2016-09-06 04:45:09)
Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c
Offline
This one resizes the images but keeps the aspect ratio. Resized image will be in the same folder.
gimp-resize.sh
#!/bin/sh
# Resize, keep aspect ratio
if [ $# -ne 4 ];
then
echo "Missing parameter!"
echo 'Usage: gimp-resize.sh "file_in" "file_out" width height'
exit
fi
gimp -d -i --batch-interpreter=python-fu-eval -b - << EOF
import gimpfu
import math
def resize(filename_in, filename_out, max_width, max_height):
img = pdb.gimp_file_load(filename_in, "")
layer = pdb.gimp_image_merge_visible_layers(img, 1)
width = int(layer.width)
height = int(layer.height)
max_width = int(max_width)
max_height = int(max_height)
if max_width <= 0:
max_width = width
if max_height <= 0:
max_height= height
if width <= max_width and height <= max_height:
print "Nothing to do, returning"
return
image_aspect = float(width) / float(height)
boundary_aspect = float(max_width) / float(max_height)
if image_aspect > boundary_aspect:
new_width = max_width
new_height= int(round(new_width/image_aspect))
else:
new_height = max_height
new_width = int(round(image_aspect*new_height))
new_name = filename_out
pdb.gimp_image_scale(img, new_width, new_height)
pdb.gimp_file_save(img, layer, new_name, new_name)
resize("${1}", "${2}", "${3}", "${4}")
pdb.gimp_quit(1)
EOF
make ecxecutable chmod +x
You can define the name in the custom action command.
Command: for file in %F; do /path/to/gimp-resize.sh "${file}" "${file%%.*}_resized.${file##*.}" 800 600;done
Forgot to mention there is some documentation about gimp-python https://www.gimp.org/docs/python/
Last edited by Misko_2083 (2016-09-06 04:45:36)
Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c
Offline
Here's another way, using Jpegtran. This will replace the original image:
for file in %N; do jpegtran -rotate 90 -copy all -outfile %N %N; done
I think it's lossy though.
Offline
[ Generated in 0.015 seconds, 8 queries executed - Memory usage: 547.13 KiB (Peak: 547.97 KiB) ]