LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-17-2010, 04:46 PM   #1
TwinReverb
Member
 
Registered: Sep 2008
Location: Misawa AB, Japan
Distribution: Slackware
Posts: 191
Blog Entries: 2

Rep: Reputation: 40
Info: resize a bunch of images for a netbook


All,

Just for information's sake, I retooled my other script (thanks to those who helped) to work for resizing images for a netbook with 1024x600. Thanks to the ImageMagick website for help with the syntax. Here's what worked for me:

Code:
#!/bin/bash

for SRCFILE in /home/robert/Pictures/*/*/*/*/*/*/*
do
   RELPATH=`echo $SRCFILE | sed -e 's/\/home\/robert\/Pictures//'`
   DESTDIR="/home/robert/tmp/portable/${RELPATH%/*}"
   if [ ! -x "$DESTDIR" ]; then
      mkdir -p "$DESTDIR"
   fi
   DESTFILE="${SRCFILE##*/}"
   #DESTFILE="`basename "$DESTFILE" .flac`"
   #DESTFILE="$DESTFILE.mp3"
   convert "$SRCFILE" -resize 1024x600\> "$DESTDIR"/"$DESTFILE"
done
Hopefully some people with netbooks find this helpful. I figure anyone with a netbook is going to put a lower size/quality on their netbook and then keep the originals (music and pictures) on a different machine or an external hard drive. Anyways, enjoy! 8-) And thanks again for all the help!
 
Old 01-18-2010, 07:45 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Good job. Here are a few suggestions for you to improve it even more.

If you're using bash version 4, there's a new globbing expression "**" that lets you work on a recursive directory tree.
Code:
shopt -s globstar     #turns it on if it isn't already.

for SRCFILE in /home/robert/Pictures/**
However, both this and your original will try to process everything in the tree, including subfolder names. It might be better to use find to filter out just the files you want.
Code:
for SRCFILE in $(find /home/robert/Pictures -type f -name "*.jpg")
Also, you shouldn't use backticks anymore. $() is the recommended way to embed commands.

Next, two comments concerning the sed command.
You can avoid the "picket fence" effect by changing the separator used in the s/// command. sed can use just about any ascii character, not just /.

Code:
RELPATH=$(echo $SRCFILE | sed -e 's%/home/robert/Pictures/%%')
But in this case you can avoid using sed entirely with another form of parameter substitution. (you will need to use backslash escapes here, however).
Code:
RELPATH=${SRCFILE/\/home\/robert\/Pictures\//)
Keep up the good work.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Resize / Scale Multiple Images carlosinfl Linux - Software 6 01-04-2010 12:06 PM
need to resize my linux partitions with ubuntu netbook remix whatleya Linux - Laptop and Netbook 4 11-29-2009 11:00 AM
Bash Script - Resize Cover.png Images XaViaR Linux - General 3 09-04-2006 12:29 PM
resize many images that are > 800x600 cadj Programming 6 06-15-2005 07:15 AM
a need simple a program to resize images while keeping the aspect ratio Necronomicom Linux - Software 3 07-10-2004 12:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration