accepting images as a list and changing the name

Here is what I have so far

#!/bin/bash

while [ $# -gt 0 ]
do
        read image
        jpegtopnm $image | pnmscale -height 200 | pnmtojpeg > $image-thumb
        echo $image-thumb
        shift
done

I sorta threw some pseudocode in there to demonstrate what I'm trying to do. . Where I am stuck is, I am trying to read in a list of images. The while/do works fine but I get confused as to how to represent all the images in the list as a single item such as '$image' because I need to scale all of them and them spit them back out on the command line with new names by adding -thumb to their names. Also I'm trying to make it JPG specific meaning if the list gets a .html file for example by accident it should skip over it. My biggest problem is I dont know how to represent a list of items as a single variable if that is the right word. Any help just to get started in the right direction is appreciated. . thank you

---------- Post updated at 04:31 PM ---------- Previous update was at 04:29 PM ----------

edit here is an update to what I have changed

#!/bin/bash

for img in *.jpg
do

        jpegtopnm $img | pnmscale -height 200 | pnmtojpeg > $img-thumb
        echo $img
        shift
done

You can remove the 'shift', it does nothing there.

Does this code do what you want, or do you still have questions?

1 Like

Hi thanks for the reply

this is what I am getting back right now im not entirely sure but it seems to be an improvement

You mean image-thumb.jpg rather than image.jpg-thumb? You first have to strip the extension off, then back on again.

jpegtopnm "$img" | pnmscale -height 200 | pnmtojpeg > "${img%.jpg}-thumb.jpg"

then if the script is ran again, you'll make thumbnails of your thumbnails, so you can skip those *-thumb.jpg files:

for img in *.jpg; do
    [[ "$img" = *-thumb.jpg ]] && continue
1 Like