accepting images as a list and changing the name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting accepting images as a list and changing the name
# 1  
Old 04-25-2012
accepting images as a list and changing the name

Here is what I have so far

Code:
#!/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

Code:
#!/bin/bash

for img in *.jpg
do

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

# 2  
Old 04-25-2012
You can remove the 'shift', it does nothing there.

Does this code do what you want, or do you still have questions?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 04-25-2012
Quote:
Originally Posted by Corona688
You can remove the 'shift', it does nothing there.

Does this code do what you want, or do you still have questions?
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

Last edited by subway69; 04-25-2012 at 08:33 PM..
# 4  
Old 04-25-2012
You mean image-thumb.jpg rather than image.jpg-thumb? You first have to strip the extension off, then back on again.

Code:
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:

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

This User Gave Thanks to neutronscott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Changing Images in HTML

Hi, I recently bought shared hosting at asphostportal.com. Now, I have little problem. Could you help me please? How to change the images after every 5 seconds in html? The images should display in the same places for every 5 seconds? can anybody send me code please. Thanks. (4 Replies)
Discussion started by: minnawanda
4 Replies

2. Shell Programming and Scripting

Bash Script to find/sort/move images/duplicate images from USB drive

Ultimately, I'm looking to create a script that allows me to plug in a usb drive with lots of jpegs on it & copy them over to a folder on my hard drive. So in the process of copying I am looking to hash check them, record dupes to a file, copy only 1 of the identical files (if it doesn't exsist... (1 Reply)
Discussion started by: JonaQuinn
1 Replies

3. Shell Programming and Scripting

Bash function accepting list of strings and error message

I have a variable strLst containing a list of strings. I want to create a function that takes the list and an error message. If the number of strings is 0 or greater than 1, I print the error message. (1 Reply)
Discussion started by: kristinu
1 Replies

4. Shell Programming and Scripting

changing the format of the list

I have a file such that List : a, b, c, d I want to list this as List a b c d however the trick is the number of arguments in the list is varies. There might be 0-7 variables . Can you help me? Please use code tags when posting data and code samples! (5 Replies)
Discussion started by: ozum
5 Replies

5. Shell Programming and Scripting

Accepting Input regardless of Case

Hi I am trying to get my script to accept input regardless if the person enters a or A. here is the portion of the code where I get the input. echo -n 'Please enter your choice:' # prompt user for input. read reply # read input echo case $reply in #... (2 Replies)
Discussion started by: DualPandas
2 Replies

6. Shell Programming and Scripting

Help with Accepting Directories as an Argument

I'm doing a script where you are suppose to start off in accepting one or more directory as an argument. How do i do this? Sorry for the nub question. (2 Replies)
Discussion started by: LinuxUser232331
2 Replies

7. Shell Programming and Scripting

Accepting A-Za-Z

Is there a way accept A-Za-z0-9 from the user from a parameter? EX. I want to take the parameter from the user even if its hEu or H3y and store it as a parameter ( $1 ) (18 Replies)
Discussion started by: puttster
18 Replies

8. UNIX for Dummies Questions & Answers

accepting input date

I how do i accept a input date in script which is lesser than a specified day? ex: to accept a date less than or equal to 100 days(from today).?:( Thanks for the help in advance.:) (1 Reply)
Discussion started by: abhi_123
1 Replies

9. HP-UX

Oracle not accepting new connections

Hi UNIX guru's, Have recently upgraded Oracle from 8i to 10g on an HP-UX (RISC) 11.11 box. At least twice a day the database stops accepting incoming connections and the following errors are observed in the various logs. The box needs to be rebooted to get everything going again. The... (4 Replies)
Discussion started by: mat_cottrell
4 Replies

10. Shell Programming and Scripting

Accepting User Input

I'm just starting out with UNIX and have figured some stuff out. I just need some help with accepting user input on the command line. For instance, I created a number counter that counts down from any positive hard coded number. But, I want the commnad line line to read "Countdown 20" where 20... (1 Reply)
Discussion started by: scott78
1 Replies
Login or Register to Ask a Question