Thanks. I'll try and see if I can write a plugin then. In the meanwhile, I managed to write a shell script to convert a file how I want (requires imagemagick and jpegtran). It turned out that my e-reader doesn't read exif metadata, so I have to actually rotate the image.
Code:
#!/bin/sh
infile="$1"
outfile="$2"
croparea=$(convert "$infile" -fuzz 10% +repage -trim -format '%[fx:w]x%[fx:h]+%[fx:page.x]+%[fx:page.y]\n' info:)
jpegtran -outfile tmp.jpg -progressive -arithmetic -crop $croparea "$infile"
read -r width height << EOF
$(identify -format "%w %h\n" $outfile)
EOF
if [ $width -gt $height ]; then
jpegtran -outfile "$outfile" -progressive -arithmetic -rotate 90 tmp.jpg
fi
rm -f tmp.jpg