I know there is a caja-image-converter plugin for this, that uses ImageMagic to rotate the images.
Images can be manipulated with gimp-python as well.
You’ll need GIMP, so install it.
apt update && apt install gimp
I made this for Thunar originaly, so this is how to use it with Caja with an extra zenity progressbar.
Create a script that will be the main script. Place it wherever you want, name it gimp-rotate.sh , and make it executable.
[code]#!/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[/code]
Now create the scripts in /home/your_username/.config/caja/scripts/ to call the main script from the Caja context (right-click) menu. Remember to change the /path/to part in the scripts and make them executable.
GIMP rotate left
#!/bin/sh
for arg
do
/path/to/gimp-rotate.sh "$arg" left
echo "#${arg}"
done | zenity --progress --pulsate --auto-close \
--text="Rotating images with <b>GIMP</b>" --title="Working"
GIMP Rotate Right
#!/bin/sh
for arg
do
/path/to/gimp-rotate.sh "$arg" right
echo "#${arg}"
done | zenity --progress --pulsate --auto-close \
--text="Rotating images with <b>GIMP</b>" --title="Working"
GIMP Rotate 180
#!/bin/sh
for arg
do
/path/to/gimp-rotate.sh "$arg" 180
echo "#${arg}"
done | zenity --progress --pulsate --auto-close \
--text="Rotating images with <b>GIMP</b>" --title="Working"
Bonus:
This is how to resize images, and keep the aspect ratio of images:
The main script gimp-resize.sh creates the resized image in the same dir
[code]#!/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[/code]
and the tcript for Caja /home/user_name/.config/caja/scripts/Gimp Resize 800x600 (change the path to the main script)
#!/bin/sh
for arg
do
/path/to/gimp-resize.sh "${arg}" "${arg%%.*}_resized.${arg##*.}" 800 600
echo "#${arg}"
done | zenity --progress --pulsate --auto-close \
--text="Resizing images with <b>GIMP</b>" --title="Working"
Tip: You can make several scripts with different size requests as well as change the output image filename.
/path/to/gimp-resize.sh "${arg}" "${arg%%.*}_resized.${arg##*.}" 500 400
^ script "image" " output image filename" max_width max_height