# requirements
su - root
apt update
# has the convert command
apt install imagemagick

vim /scripts/create_thumbs.sh 

#!/bin/bash
THUMBS_FOLDER=/path/to/images/thumbnails
for file in /path/to/images/*
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=`echo $IMAGE_SIZE | sed 's/x/ /g' | awk '{print $1}'`
    HEIGHT=`echo $IMAGE_SIZE | sed 's/x/ /g' | awk '{print $2}'` 
    #This line convert the image in a 200 x 150 thumb 
    filename=$(basename "$file")
    extension="jpg" # convert every kind type of image to jpg
    # extension="${filename##*.}" # preserve original extension
    filename="${filename%.*}"
    # convert -sample 200x150 "$file" "${THUMBS_FOLDER}/${filename}_thumb.${extension}" 
    # convert -resize 20% "$file" "${THUMBS_FOLDER}/${filename}_thumb.${extension}" 
    echo "=== currently processing $file ==="
    convert -resize 300 "$file" "${THUMBS_FOLDER}/${filename}_thumb.${extension}" 
  fi 
done

manpage

convert.man.txt

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin