You cannot use %F
twice in a command like that, because %F
gets replaced by the names of every file selected. For example, a command of sh
with parameters -c 'printf "%%s\n" "$@" > foo' %F %F
will create a file named foo
with the names of every file selected, twice. Therefore the convert
command that actually runs is:
convert file1.jpg file2.jpg ... -quality 80% file1.jpg file2.jpg ... fileN.jpg-80q.jpg
And since the last file is taken to be the output file name, only it will matter.
What you can do is wrap your command in bash -c
and run a for loop:
bash -c 'for i; do convert "$i" -quality 80% "${i/%.jpg/-80q.jpg}"; done'
(where I am assuming that all files end with .jpg
)
In an action, you will have bash
as the command, and for the parameters:
-c 'for i; do convert "$i" -quality 80%% "${i/%%.jpg/-80q.jpg}"; done' - %F
You can make this more complicated to handle any extension, at which point you might as well skip Actions and use scripting.
There's a powerful image suite called ImageMagick. Among its tools you can find a display
utility, which is used, as it is obvious from its name, to display various graphic formats from the console. Here are several examples of its usage:
display -geometry 500x500 image.png
This will open your image in the window with the selected size. Moreover, a small window representing the full image will be opened nearby, so you can move the selection rectangle to show the desired parts of your image.
display -extract 300x300+50+50 image.png
This command will show you the part of your image with the size of 300x300 pixels and with the offset of 50 pixels from its top left corner.
You can find the full list of its options in man display
. Also there's an extensive manual here.
ImageMagick also provides other useful tools. For example, this will show the info about the image (its type, dimensions, size):
identify "my image.png"
In order to display your image without the margins we should measure them to crop them later. I opened your dummy picture in Gimp to make things faster. So the margins are:
Left - 1070px
Right - 880px
Top - 70px
Bottom - 100px
If the original size of you picture is 8640x960
then the image size without the margins will be: X=8640-1070-880=6690
and Y=960-70-100=790
, i.e. 6690x790
.
And now we'll combine -geometry
and -extract
options to produce the output:
display -geometry 500x500 -extract 6690x790+1070+70 raw.png
(set the size of output window to 500x500, crop the image to the new size 6690x790 and shift the crop area by 1070px horizontally and by 70px vertically from the top left corner of the image).
Here's what I've got (I moved the selection to the right for more clearness):
All these calculations are a bit tedious, but if you've got static margins (it seems that your images are produced automatically), then you can calculate them once and apply to all your images. Or even make some script to automate this (that's an improved version of the script - it calculates iteration using identify
command of ImageMagick):
#!/bin/bash
if [ $# -lt 2 ] ; then echo "usage: reviewimage output_resolution image_name" ; exit ; fi
OUTRES=$1
IMAGE=$2
# Some sanity or error checks, change as you see fit
if [ $OUTRES -lt 100 ] || [ $OUTRES -gt 1000 ] ; then echo "error: Invalid resolution" ; exit ; fi
if ! [ -e "$IMAGE" ] ; then echo "error: Image doesn't exist" ; exit ; fi
SHIFT=50 # Relative position of output window from top left corner of the desktop
IMAGE_X=$(identify "$IMAGE" | grep -o '[0-9]*x960 ' | cut -d'x' -f1)
IMAGE_Y=960
ITER=$(( $IMAGE_X / 960 ))
MARGIN_T=70
MARGIN_B=100
MARGIN_L=$(( -5 + $ITER * 119 ))
MARGIN_R=$(( -40 + $ITER * 102 ))
EXTRACT_X=$(( $IMAGE_X - $MARGIN_L - $MARGIN_R ))
EXTRACT_Y=$(( $IMAGE_Y - $MARGIN_T - $MARGIN_B ))
display -geometry ${OUTRES}x${OUTRES}+${SHIFT}+${SHIFT} -extract ${EXTRACT_X}x${EXTRACT_Y}+${MARGIN_L}+${MARGIN_T} "$IMAGE"
Save this script under the name reviewimage
somewhere. Then run the commands below:
sudo cp reviewimage /usr/local/bin/
sudo chmod 755 /usr/local/bin/reviewimage
Now you can call this command from every folder with your images. For example, to open a preview of your image raw10.png
with the size of 700x700
:
reviewimage 700 raw10.png
If the name have spaces in it, use quotes:
reviewimage 700 "raw 2.png"
If the margin calculation formula becomes imprecise with high iterations you can use array of margin values. Adjust each margin value as you see fit. Script below shows the principle. It is filled with the values for iterations 1-10, add more inside the brackets with the space as a divider:
#!/bin/bash
if [ $# -ne 1 ] ; then echo "usage: convertimage image_name" ; exit ; fi
if ! [ -e "$1" ] ; then echo "error: Image doesn't exist" ; exit ; fi
IMAGE=$1
IMAGE_X=$(identify "$IMAGE" | grep -o '[0-9]*x960 ' | cut -d'x' -f1)
IMAGE_Y=960
ITER=$(( $IMAGE_X / 960 ))
MARGIN_T=70
MARGIN_B=100
MARGIN_L=(0 114 233 352 471 590 709 828 947 1066 1185)
MARGIN_R=(0 80 180 280 380 480 580 680 780 880 980)
EXTRACT_X=$(( $IMAGE_X - ${MARGIN_L[$ITER]} - ${MARGIN_R[$ITER]} ))
EXTRACT_Y=$(( $IMAGE_Y - $MARGIN_T - $MARGIN_B ))
convert "$IMAGE" -crop ${EXTRACT_X}x${EXTRACT_Y}+${MARGIN_L[$ITER]}+${MARGIN_T} "${IMAGE%.png}_cropped.png"
This script performs cropping of the image instead of displaying it, so this converted image can be viewed in any program. It needs only one parameter - image name:
convertimage "raw 9.png"
Best Answer
From quick reading of this, apparently
convert
calls this option-flop
for horizontal mirroring, and-flip
for vertical. All I needed to do was