I need a bash script that gets all the images inside a specific folder; take their resolution, and if it is below the minimum, do nothing, otherwise create a middle finger (200x150 pixels).
I am using Imagemagick on Windows. But on linux, I cannot use the same script, so I need to write a new script.
This is what I have come up with so far.
#!/bin/bash for files in /path/to/image/* do TESTFILE=`echo "$files" | sed 's/|/ /g' | xargs file -b | awk '{print $1}'` while read F CHECKSIZE=`file "$TESTFILE" -b | sed 's/ //g' | sed 's/,/ /g' | awk '{print $2}' | sed 's/x/ /g' | awk '{print $1}'` if [ $CHECKSIZE -ge 200 ]; then convert -sample 200x150 "$F" "$F{_thumb}" fi done done
But when I run this script, it does not give me thumbnails and does not give me any errors. I am new to these scenarios.
Update:
I came up with this script, thanks to everyone. But now I need one more help. Now I want to save the new image in a folder inside the image folder. For example, / home / image has all the files. I want thumb images to be saved in / home / image / thumbs . I also want to rename files as filename_thumb.jpg , but the problem with the following script is storing as filename.jpg_thumb .
#!/bin/bash THUMBS_FOLDER=/home/temp/thumbs for file in /home/temp/* do # next line checks the mime-type of the file IMAGE_TYPE=`file --mime-type -b "$file" | awk -F'/' '{print $1}'` if [ x$IMAGE_TYPE = "ximage" ]; then IMAGE_SIZE=`file -b $file | sed 's/ //g' | sed 's/,/ /g' | awk '{print $2}'` WIDTH=`identify -format "%w" "$file"` HEIGHT=`identify -format "%h" "$file"` # If the image width is greater that 200 or the height is greater that 150 a thumb is created if [ $WIDTH -ge 201 ] || [ $HEIGHT -ge 151 ]; then #This line convert the image in a 200 x 150 thumb filename=$(basename "$file") extension="${filename##*.}" filename="${filename%.*}" convert -sample 200x150 "$file" "${THUMBS_FOLDER}/${filename}_thumb.${extension}" fi fi done
source share