Loop through directory convert jpg to png


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Loop through directory convert jpg to png
# 1  
Old 04-16-2011
Loop through directory convert jpg to png

Hi guys. I will be frequently needing to convert .jpg files to 183x183 .png thumbnails. I can't quite seem to wrap my head around how to make a for loop to do this.

With the help of my friend (who may have mislead me, I'm quite confused) I've got this.

This is bash

the command is: pngify <source directory> <destination directoy>
Code:
for picture in $(?) ====> I'm quite sure this part is wrong...
do
        echo ${picture%.*}>picturewithoutext     =====|This part is to remove the 
        picnoext=`cat picturewithoutext`               =====|extension so I can name 
        rm picturewithoutext                   ======== ===|the new file the same thing with a .png

        convert -size 183x183 $1/$picture $2/$picnoext.png  
done

Yes, I am very new to shell scripting ^_^;;

Last edited by Drayol; 04-16-2011 at 10:09 PM.. Reason: Please use code tags
# 2  
Old 04-17-2011
You don't need temporary file for removing file's extension. Try this:
Code:
#!/bin/sh
for picture in `ls $1`
do
        picnoext=${picture%.*}
        echo "convert -size 183x183 $1/$picture $2/$picnoext.png"
done

# 3  
Old 04-17-2011
Quote:
Originally Posted by bartus11
You don't need temporary file for removing file's extension. Try this:
Code:
#!/bin/sh
for picture in `ls $1`
do
        picnoext=${picture%.*}
        echo "convert -size 183x183 $1/$picture $2/$picnoext.png"
done

why the use of ls ? use shell expansion
Code:
for picture in $1/*

# 4  
Old 04-17-2011
Did you try it? Smilie
With `ls $1`:
Code:
[root@linux sh]# ./a.sh /root/sh /root/jj
convert -size 183x183 /root/sh/a.sh /root/jj/a.png
convert -size 183x183 /root/sh/file.jpg /root/jj/file.png

and with $1/*:
Code:
[root@linux sh]# ./a.sh /root/sh /root/jj
convert -size 183x183 /root/sh//root/sh/a.sh /root/jj//root/sh/a.png
convert -size 183x183 /root/sh//root/sh/file.jpg /root/jj//root/sh/file.png

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert values in an array using a loop

I have a headerless array of 1000 columns x 100000 rows. The array only contains 4 values; 0/0, 0/1, 1/1, ./. Here I am showing the 1st 3 rows and columns of the input array 0/0 0/0 1/1 0/1 0/1 0/1 0/0 ./. 0/0 0/0 0/0 0/0 I would like to convert the values in... (9 Replies)
Discussion started by: Geneanalyst
9 Replies

2. Shell Programming and Scripting

Convert jpg file to binary format

Hi Team, Here's the requirement. I have a image file in jpg format in unix. Now I need to i. convert the jpg format to binary format ii. followed by loading the binary file to Oracle db. Can anyone help me out? Thanks Krishnakanth Manivannan (4 Replies)
Discussion started by: kmanivan82
4 Replies

3. Shell Programming and Scripting

Sendmail Png Attachments

I use sendmail to send html emails, my script works perfect and sends email with plain text attachment. Now i need to attache png file to the email and this attachment part is not working. ( echo "From: $FROM" echo "To: $TO" echo "MIME-Version: 1.0" echo "Subject: $SUBJECT" echo... (4 Replies)
Discussion started by: posner
4 Replies

4. UNIX for Dummies Questions & Answers

Loop through directory and extract sub directory names

I am trying to loop through folders and extract the name of the lowest level subfolder I was running the script below, it returns /bb/bin/prd/newyork /bb/bin/prd/london /bb/bin/prd/tokyo I really want newyork london tokyo I couldn't find a standard variable for the lowest level... (1 Reply)
Discussion started by: personalt
1 Replies

5. Programming

Converting XImage to PNG

i was able to make a connection to X server and get a screen shot using XGetImage, now, im unable to save this XImage to any good format like PNG, i found a code that saves it to bitmap, but the resulted bitmap file is massive, is there anyway i can save this XImage to PNG directly? thanks; (7 Replies)
Discussion started by: JonhyM
7 Replies

6. Shell Programming and Scripting

how to convert this to a loop

I have a list of files in the same directory need to do the following cut -d "=" f2 file1 > file1_result cut -d "=" f2 file2 > file2_result ... past file1_result file2_result .... >file_sum How to do this in a loop? Thank you. (3 Replies)
Discussion started by: ksgreen
3 Replies

7. Shell Programming and Scripting

Rename all ".JPG" files to ".jpg" under all subfolders...

Hi, Dear all: One question ! ^_^ I'm using bash under Ubuntu 9.10. My question is not to rename all ".JPG" files to ".jpg" in a single folder, but to rename all ".JPG" files to ".jpg" in all subfolders. To rename all ".JPG" to ".jpg" in a single folder, for x in *.JPG; do mv "$x"... (7 Replies)
Discussion started by: jiapei100
7 Replies

8. Shell Programming and Scripting

makefile to convert .jpeg to .png thumnails

Hello! I'm desperately trying to write a makefile that converts and scales jpeg files to png files in subdirectories I want to use netpbm, so I just need the commands: anytopnm pnmscale pnmtopng For various reasons i want to use a makefile. This is the first time i use the make tool... (1 Reply)
Discussion started by: henningbaer
1 Replies

9. Shell Programming and Scripting

Simple BASH shell script to rename webcam jpg and copy into a new directory.

System: Ubuntu Intrepid Ibex I'm running webcamd as a sort of "security" program, but I need a script that will archive my webcam.jpg files. So, take the following file: /home/slag/www/webcam.jpg Rename it--preferably with a time stamp. Place it in say: /home/slag/www/history/ ... (4 Replies)
Discussion started by: robfindlay
4 Replies

10. UNIX for Dummies Questions & Answers

Print the content of a directory in jpg file

Is there any possible way to print the contents of a directory to a .jpg file? I have a list of thumbnails (e-books) which I want to share (+500) but I don't know how to make this. I would appreciate a lot any comments regarding this issue. (4 Replies)
Discussion started by: agasamapetilon
4 Replies
Login or Register to Ask a Question