Philips Tech Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 5 August 2010

How to resize photos with Bash shell script

Posted on 05:53 by Unknown

Ivo Kaspar wrote this guide to resize multiple images using simple Bash shell script. It uses the convert program from ImageMagick, the swiss-army knife of command line image processing software. The original guide is edited and rewritten in some places.




You'll find this guide interesting if you want to resize a lot of pictures to upload to your website or email them. First you need to install the 'imagemagick' package if it is not installed on your computer. To install imagemagick, copy this line into your terminal application and confirm with your password. Close the terminal after it finished the installation.
sudo apt-get install imagemagick




Open the text editor and paste these lines into it:



#!/bin/bash
for i in *.JPG; do convert $i -resize 10% $(basename $i .JPG).jpg; done


Save the document and give it a sensible name to recognize it later on.




Note that this script will work only with files that has uppercase '.JPG' extension and renames them to lower case '.jpg'. Some digital cameras follow this kind of file naming schema. You may like to change this to suit your needs.According to its manual page ImageMagick can read, convert and write images in a variety of formats (about 100) including GIF, JPEG, JPEG-2000, PNG, PDF, PhotoCD, TIFF and DPX.



If you want to define the size of the picture replace the "10%" with the amount of pixels you want it to have, 400x600 is a usable resolution. Of course it is also possible to keep the relative scale with any value instead of the “10” followed by "%" postfix. To change the file format to something other than “.JPG” you have to change the last “.JPG” into the format of your choice.



If you want to rename the pictures, you have to add something behind the "(basename $i .JPG)" and the ".JPG". I usually add an "­-s" (for small) to indicate the reduced size of the pictures.



When you run the script it will proceed to resize all the pictures in the current folder, but not in any sub folders.
Keep in mind that:


  • Small pictures are small forever, you can't revert them.

  • The filenames must not contain any space

  • The filename must match to the first two “.JPG” or “.jpg”



Examples Scripts:




# capital .JPG files, 10% size, no rename, it will overwrite the old
pictures
#!/bin/bash
for i in *.JPG; do convert $i -resize 10% $(basename $i .JPG).JPG; done
---
# lower case .jpg files, 10% size, renamed to capital .JPG (with ubuntu it's
a different file, not with windows!)
#!/bin/bash
for i in *.jpg; do convert $i -resize 10% $(basename $i .jpg ).JPG; done
---
# capital .JPG files, 10% size, adds an -s in the name of the new ones,
keeps the old ones
#!/bin/bash
for i in *.JPG; do convert $i -resize 10% $(basename $i .JPG)-s.JPG; done
---
# capital .JPG files, 600x400 size, no rename, it will overwrite the old
pictures
#!/bin/bash
for i in *.JPG; do convert $i -resize 600x400 $(basename $i .JPG).JPG; done

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in bash, shell | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Google Apps Script for Google Sites
    Google Apps Script started as functions for Google Spreadsheets. Today Apps Scripts have evolved into powerful development environment for e...
  • Naranda Muni Assocation
    Juan says 'I now dub thee, president arky ' Initiation into Hipatia community Browsing this blog on Nokia N95 at the IFFK in Kerala...
  • Acer Aspire One Battery Charging Problem
    If you believe amnesia is a malady that effects humans, think again. Recently a Acer Aspire One netbook landed on my table with a similar p...
  • PyCon India 2009
    Most action happens on conference sidelines PyCon India 2009 is no expection. You can always watch the recordings of talks later on. Catch...
  • Prayas The Tinkerer
    Ran into Prayas the tinkerer while in Bangalore. He introduced me to two of his really interesting projects. CANOPY: temporary roofs for t...
  • Free Software Camp for Ngo's and Civil Society Groups in Delhi, India
    Free Software Workshop for NGOs and Civil Society Groups Effectively compute and communicate in your local language using free and open sour...
  • Swathi Sangeethotsavam 2010
    The thunderstorm lasted all night, it was raining all sunday afternoon. The lake water is rising again, I resist the idea of going for a swi...
  • ALSA Jack Sense problem in Jaunty
    Update: Ubuntu Lucid user should read the this updated post Headphone jack sense problem in Ubuntu 10.04 Lucid Lynx instead. The newly or...
  • National Open Source Conference of Afghanistan (NOSCA) 2013
    This week National Open Source Conference of Afghanistan (NOSCA) starts in Jalalabad, Afghanistan. The event is organized by the National I...
  • Startup Investment Hour in Hanoi
    Opportunities abound for those who think big in Vietnam. Recently 5Desire , a local startup accelerator organized Startup Investment hour. T...

Categories

  • "compiz-fusion"
  • "film making"
  • "Graphic Design"
  • "martial art"
  • 01-18-2012
  • 10.04
  • 10.10
  • 3dprinting
  • 9.04
  • a11y
  • accerciser
  • accessibility
  • Activism
  • adobe
  • aegis
  • africa
  • AIR
  • alsa
  • Andhra Pradesh
  • android
  • angling
  • Animals
  • apache
  • apple
  • apport
  • Apps Script
  • architecture
  • ardour
  • arduino
  • ARM
  • art
  • audio description
  • bangalore
  • barcamp
  • barcamphanoi
  • barcampkl
  • barcamppp
  • barcampsaigon
  • barcampvte
  • bash
  • bcy2011
  • beercamp
  • biofuel
  • bittorrent
  • blackout
  • blender
  • blind
  • blogging
  • book
  • boot2gecko
  • braille
  • broadcom
  • bugs
  • bzr
  • Calicut
  • cambodia
  • canon
  • Canopy
  • cartoons
  • cat
  • CC
  • CDMA
  • censorship
  • CHDK
  • children
  • china
  • Chromium
  • Climate Change
  • cms
  • Comedy
  • comics
  • command line
  • compiz
  • Computational Linguistics
  • cpan
  • Creative Commons
  • cyanogenmod
  • DAISY
  • debian
  • delhi
  • design
  • dhvani
  • django
  • documentation
  • dontzap
  • dots
  • drupal
  • drush
  • earth hour
  • easy_install
  • eclipse
  • Ecuador
  • embedded linux
  • Environment
  • espeak
  • events
  • fennec
  • ffmpeg
  • film
  • film making
  • firefox
  • firefox3
  • firefox4
  • firefoxOS
  • firmware
  • fishing
  • fossasia
  • free culture
  • free software
  • fsfs
  • fx4
  • G1
  • gadgets
  • gdm
  • geek humour
  • Gimp
  • GISS
  • git
  • gnewsense
  • gnome
  • google
  • gta02
  • GUI Testing
  • hack
  • hackable1
  • hacker
  • handbrake
  • hanoi
  • hanoitweetup
  • hardware
  • hardy heron
  • hipatia
  • html5
  • humour
  • hunspell
  • ICANN41
  • iceweasel
  • identi.ca
  • iffk
  • IISE
  • india
  • Indian Languages
  • intel
  • interaction design
  • internet
  • intersat
  • Intrepid
  • Intrepid Ibex
  • ipod
  • jam
  • jaunty
  • Java
  • Javascript
  • josm
  • karmic
  • kerala
  • kernel
  • keyboard
  • kid
  • kiddy video
  • kids
  • kinect
  • kiosk
  • l10n
  • laos
  • launchpad
  • ldap
  • libreoffice
  • Linux
  • local weather
  • lucid
  • machine translation system
  • maemo
  • mallard
  • manga
  • maps
  • maverick
  • mediawiki
  • meego
  • mencoder
  • merkaartor
  • micro-blogging
  • midori
  • Mobile
  • moblin
  • mod_pagespeed
  • modem
  • mozcamp
  • mozilla
  • mplayer
  • music
  • mwc2012
  • myanmar
  • mymozl10n
  • mysql
  • n70
  • nature
  • nedumangad
  • neo freerunner
  • Neo1973
  • nepal
  • netbooks
  • NGO
  • NLP
  • NLTK
  • Nokia
  • Nonprofits
  • notify-osd
  • NUI
  • nvda
  • OLPC
  • ooffice
  • openDNS
  • openmoko
  • openNI
  • openOffice
  • openoffice.org
  • OpenStreetMap
  • orca
  • oscar
  • OSM
  • packaging
  • PDF
  • people
  • perl
  • Pets
  • photography
  • pipa
  • pokhara
  • postfix
  • potlatch
  • powershot
  • programming
  • pune
  • puppylinux
  • python
  • pythonegg
  • radio show
  • Recycling
  • red nose day
  • rms
  • RND
  • robots
  • rockbox
  • rubber
  • ruby
  • rural
  • s60
  • sahana
  • samba
  • samsung
  • scipy
  • security
  • SFD2011
  • shell
  • silk
  • singapore
  • skype
  • social media
  • software-center
  • softwarefreedomday
  • solar
  • solar eclipse
  • sopa
  • speakers
  • spins
  • stallman
  • startups
  • system-adminstration
  • t-shirt
  • tablet
  • tactile watch
  • tea shops
  • technology
  • tee
  • terminal
  • Testing
  • theatre
  • tibet
  • tracker
  • travel
  • trek
  • trekking
  • tux4kids
  • tuxmath
  • tv
  • tweets
  • twitter
  • ubuntu
  • UNR
  • uTouch
  • UX
  • UXA
  • vagrant
  • VCS
  • veli
  • vidarbha
  • video
  • virutalization
  • vsat
  • w3c
  • watches
  • water from dew
  • weather stations
  • weave
  • web automation
  • web standards
  • web testing
  • web2py
  • webmaker
  • Wiki
  • wikia
  • wikipedia
  • Windows
  • Windows XP
  • wordpress
  • wvdial
  • X-Window-System
  • X11
  • xorg
  • yelp
  • Zii
  • ZTE

Blog Archive

  • ►  2013 (17)
    • ►  September (1)
    • ►  August (1)
    • ►  July (1)
    • ►  June (2)
    • ►  May (3)
    • ►  April (1)
    • ►  March (1)
    • ►  February (5)
    • ►  January (2)
  • ►  2012 (26)
    • ►  December (3)
    • ►  November (1)
    • ►  October (1)
    • ►  July (1)
    • ►  June (3)
    • ►  May (6)
    • ►  April (1)
    • ►  March (8)
    • ►  January (2)
  • ►  2011 (43)
    • ►  December (2)
    • ►  November (7)
    • ►  October (8)
    • ►  September (4)
    • ►  August (5)
    • ►  June (1)
    • ►  February (6)
    • ►  January (10)
  • ▼  2010 (73)
    • ►  December (17)
    • ►  November (5)
    • ►  October (10)
    • ►  September (3)
    • ▼  August (8)
      • Origamic pop-up greeting cards
      • Ralink Wireless support in Puppy Linux
      • Ubuntu Netbook Remix (UNR) UI on Ubuntu 10.04 Luci...
      • Universal Braille Kit (UBK)
      • Nortec SurfBoard Running Ubuntu 10.04
      • How to resize photos with Bash shell script
      • THE THIRD WAVE A Volunteer Story
      • Bait Seaside Restaurant, Kovalam beach
    • ►  July (9)
    • ►  June (4)
    • ►  March (5)
    • ►  February (7)
    • ►  January (5)
  • ►  2009 (108)
    • ►  December (7)
    • ►  November (10)
    • ►  October (8)
    • ►  September (6)
    • ►  August (8)
    • ►  July (4)
    • ►  June (5)
    • ►  May (6)
    • ►  April (15)
    • ►  March (15)
    • ►  February (9)
    • ►  January (15)
  • ►  2008 (33)
    • ►  December (33)
Powered by Blogger.

About Me

Unknown
View my complete profile