Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8695605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:04:52+00:00 2026-06-13T01:04:52+00:00

I need a bash script that get all the images inside some specified folder;

  • 0

I need a bash script that get all the images inside some specified folder; take their resolution and if it is below minimum then do nothing, otherwise create a medium thumb image (200×150 pixels).

I am using Imagemagick in Windows. But on linux, I can’t use the same script so I need to write a new script.

This is what i have come up 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 is not giving me thumbnails nor giving me any errors. I am pretty new to these scripting.

Update :

I have come up with this script, thanks for all. But now i need one more help. Now i want to store the new image in a folder inside the images folder. For example, /home/image is where all the files are. I want thumb images to store in /home/image/thumbs. Also i want to rename files as filename_thumb.jpg, but the issue with following script is it 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:04:53+00:00Added an answer on June 13, 2026 at 1:04 am

    Another approach without use imageinfo:

    Please remember to change the images path, in my case I use a folder called imgs at the same folder level.

    Copy the content in a file called create_thumbs.sh, and paste next code:

    #!/bin/bash
    THUMBS_FOLDER=/home/image/thumb
    for file in /home/image/*
    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}'`           
          # 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
    

    To call it:

    bash create_thumbs.sh
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make a bash script that takes user input and does some
For a Bash completion script I need to get all the variables from an
I'm writing a bash script to get some podcasts. The problem is that some
I have a bash script that I need to write my password to run
I need to write a quick bash script that asks the user which mac
I got a variable in a bash script that I need to replace. The
I have a bash script which need to execute some php scripts and to
I need to output some text as bash script, but in a script. I
Inside a bash script function, I need to work with the command-line arguments of
I need a bash script that does the following: Starts a background process with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.