Recursive Batch Image Resizing in Linux

24 01 2009

So today I needed to resize a photo archive of 3000 images spread out in sub-folders for every year and month… Fortunately, in linux with a bit of research I got it!

First off, you must download ImageMagick – if you are running Ubuntu, LinuxMint or a similar distro with APT you can simply do:

sudo apt-get install imagemagick

Then you can cd (change directory) to the folder containing the pictures that are to be resized. For example:

cd /home/username/Pictures/toShrink

Now for example, if you only need to resize the .jpgs in this folder to 800px wide do:

mogrify -resize 800 *.jpg

NOTE: This is case sensitive, .jpg is not .JPG.  It is likely that you will have to run any of these commands for all file extention variations in your collection.  For instance once with *.jpg, then *.JPG, then *.jpeg then *.JPEG

To resize them to a specific size (distorting their aspect ratio if necessary) do:

mogrify -resize 800x600! *.jpg

To resize them to 50% of their original size do:

mogrify -resize 50% *.jpg

To resize them to a specific pixel content (effectively scaling small images up and large images down to a uniform size while maintaining aspect ratio) of their original size do:

mogrify -resize 480000@ *.jpg

Basically, the above number is 800*600=480000px.  Whether it be 800×600 or 600×800 or even 1200×400 pixels in size the image contains a total of 480000 pixels.  This will scale the images so that they contain X number of pixels.

Since many of my photos were different aspect ratios, different sizes and different orientations, some even panoramas, I settled for the above option.  I used 2000000@ which made all of my 4:3 photographs 1632×1224 and the panoramas similarly sized – not totaly precise but at least now all the pictures taken by different cameras at different resolutions are all roughly the same size!

Now RECURSIVE BATCH IMAGE RESIZING:
To resize all .jpgs in this folder and every sub folder contained within it (recursively) – FIRST DO A TEST RUN! – the following command will NOT change files, it will just output to console the commands that it would be performing:

find ./ -name "*.jpg" -exec echo mogrify -resize 800 {} \;

You should see outputted to console the mogrify command for ONLY the files that you want to resize.

mogrify -resize 800 ./subFolderName/fileName.jpg 

This is an example output that I get:

mogrify -resize 800 ./2007/12_December/IMG_0172.jpg
mogrify -resize 800 ./2007/12_December/IMG_0199.jpg
mogrify -resize 800 ./2007/12_December/IMG_0166.jpg
mogrify -resize 800 ./2007/04_April/2007-04-25_ph101_12.jpg
mogrify -resize 800 ./2007/04_April/041207_13491.jpg
mogrify -resize 800 ./2007/04_April/2007-04-25_ph101_13.jpg

Make sure that the options are correct and that it is modifying the correct files.  Use caution, test it out on a few images first..  This overwrites the original file so make sure that you have a backup of everything just in case something goes wrong.
If it all looks good and you’re ready to go, simply remove the echo .
This is the final command that I used (resizing 4:3 images to around 1632×1224):

find ./ -name "*.jpg" -exec mogrify -resize 2000000@ {} \;

Remember, it is case sensitive.  Run it again for *.JPG , *.jpeg, and *.JPEG!

ImageMagick can do a whole lot more, things such as image conversions.. like JPG to PNG :)

convert *.jpg imageSeriesName.png

Check out the ImageMagick site to learn more about what you can do with this extremely powerful non-graphical graphics program! :D

Good luck guys, hope this post helps make life easier for a fellow creature of the net!





Tweak Dial up with Proxy Caching – QUESTIONS!? + answers!

10 01 2009

Okay so I’m going crazy trying to come up with an ideal tweaked setup for my mom’s new laptop.  I must get it perfect before I send it out to the middle of nowhere 24kbps dialup country.

Using a localhost DNS server probably does improve performance, but i’m not sure about a proxy.

These are my questions in response to THIS Tweak guide:

I’ve been attempting to do proxy caching technique using Squid, but I really am wondering exactly how it functions and I have some doubts as to whether or not it really works.

So from my understanding this is how it all works:

  1. User clicks link on a webpage:
  2. Client contacts DNS server (ideally localhost, if DNS entry isn’t there it pulls it slowly from the net ISP or OpenDNS server)
  3. Client browser requests webpage from browser cache, if not found, it asks for it from localhost proxy cache, if it’s not there it pulls it slowly from the net.
  4. Files are slowly downloaded and written to proxy cache, then written to browser cache creating an unfortunate redundant data and drive usage? :(
  5. Webpage is rendered in browser.

Next time user goes to that page, ideally the content is cached locally and it will load quickly from the harddrive.

Now my major question is -
I can see how a localhost proxy cache would be useful if you had multiple people logging into the same machine where their browsers have seperate caches – but is there any benefit to proxy cache in a single user setting?

Well, I’ve concluded that proxy cache is the way to go, despite it’s added difficulty for two reasons:
1. Mozilla Firefox has the TERRIBLE habit of ERASING the entire disk cache every time it crashes or closes improperly…This renders making a huge disk cache in firefox pointless since it will likely be lost.
2. The proxy cache provides much more in terms of configuration options and works for multiple users and multiple applications.

Does the browser cache and the proxy cache function in the same way? Do they save everything?  .JS, .SWF, .PNG, etc… ?  Wouldn’t it be best to then disable the browser cache to avoid redundant disk usage?

Yes, it seems to cache everything, even cookies.  As far as I can tell the browser disk cache can be disabled when using proxy cache.

What happens if a dial up user clicks Stop – does the proxy server continue to load the files for that page – actually causing their internet speed to slow down??

Well, I’ve only dealt with Polipo caching proxy and apparently it when the user clicks Stop, Polipo stops loading the file but caches the partially downloaded file so that it continue downloading it later in case the user requests it.  However, I think I read that many other proxies do not cache incomplete files…

Haha sorry for the rant but if anyone knows the answer to any of these questions.. please please post :)   Thanks!





Winter Vacation, To-Do List Placation

31 12 2008

Well, the madness of the end of semester is over.  An uneventful (which is good) Christmas has passed – all I did was sit back and watch Slumdog Millionaire, which is a surprisingly awesome movie.

It feels as if I’m making no progress at chipping away at the long to-do list of things I wanted to catch up on during this vacation..  I’m suspecting that to-do lists really do not work.  It seems like, despite the fact I’m barely working two days a week right now during break, I still am falling behind.  There’s so much to do on my list and yet, bam, suddenly tons of bills come, birthdays, holidays, other responsibilities, etc.. The original ToDo list just sits there and pretty much now there’s a NEW ToDo list of more urgent tasks.

I need to somehow pay for tutition which means generating $1k in two days which doesn’t seem possible – this would not have been a problem if my winnings from QuakeCon 2008 QuakeLive had been what they were supposed to be.. They told me that I won $2000, but the check that arrived in the mail was $1000..it’s hard to complain since it’s prize money but still I was really counting on that money for school.  Oh well, guess it’ll be a high interest payment plan for this semester.

I need to learn Adobe AfterEffects well enough to start a level 2 course even though I’ve never taken level 1.. I suspect that during my sleep deprived final two weeks of classes I managed to totally forget to go to my Science of Color and Light final and so I recieved an INCOMPLETE.. Ugh, so disappointing, don’t know how..I thought I went.. I did.. didn’t I?  I don’t remember anything really from the last weeks of school.  It’s kinda frightening.  Next semester I need to make sure that I sleep no matter what happens.

Anyway, so the good thing is I’ve recovered my home built desktop computer from it’s neglected, virus riden state.  What really did it under was a virus that I aquired during an epic two day attempt  at installing the patch for  Resident Evil 4 / Biohazard.  This is a patch that is necessary since the PC port of the game was a total hack job and should never have been released without more work.  I failed miserably in the end at patching the game (trust me, building a computer and setting it up as a headless linux server is easier than patching this game).  And well.. the good news is, now the computer is all fixed up again as a dual-boot machine with a minimal install of WindowsXP sp3 (just for games) and LinuxMint 6 (for everything else).  It’s still not tweaked as nicely as my old Ubuntu Studio setup, but it does the job for now and I found this FlickR group of 360 degree photos to use for the fully rotatable skybox.

Well.. time to enjoy some gaming at long last.. Enemy Territory Quake Wars and HalfLife: Episode One (FINALLY!)





Zenwalk Linux 5.2 XFCE on a Dell Dimension L866r

19 11 2008

Well to get things started here on wordpress I might as well post these notes that I wrote that cover the key points necessary to install Zenwalk Linux on a Dell Dimension L866r (PIII-866, 382mb PC133).  I wish I had these notes when I was attempting this setup, as it would have saved me many hours of trolling through the web and a frustrating amount of trial and error..

I worked on this system for a Windows-user friend of mine and, after wiping their virii infected Windows ME install, my primary objective was to find the most user-friendly, fastest distro with the best Flash player performance.  This isn’t an easy feat due to the sorry state of Adobe’s one-man Flash for linux project – he’s doing a great job, but seriously, Adobe should get their priorities straight, especially with the increasing low-end linux based netbooks that are flooding the market.  So anyway, I tried several distros of linux on this system and found Zenwalk using XFCE desktop manager to be without a doubt the best, speediest, user-friendly desktop linux – with the smoothest full-screen Flash video playback.

Here’s my cheatsheet:

Dell Dimension L866r w/Dreamwalk Linux 5.2 xfce

  1. Install Zenwalk
  2. > netpkg upgrade
  3. Download Win98 drivers for Wireless RTL8185 (LINK)
  4. Install Windows Driver using Ndiswrapper (LINK): > Ndiswrapper -i driverfilenamehere.inf
  5. Make sure driver shows up: > Ndiswrapper -l
  6. > Ndiswrapper -m
  7. > Depmod -a
  8. > Modprobe ndiswrapper
  9. Wireless Settings: DHCP, Wep hex ##########

I ran into an annoying issue where the desktop would show up at the correct resolution but when you booted and hit the GDM login screen the resolution was too high and the screen would pan around when you moved the mouse to the screen edge..  The desired resolution was 1024×768.  The solution was:

To fix XFCE GDM login screen panning:
Edit /etc/Xorg.conf ; modes:
Delete 1280×1024 (or every resolution that is higher than your desired resolution)

Then there was an annoying bug that caused XFCE to restart every time the xterm terminal was launched…

To stop xterm terminal from restarting XFCE (intel video issue):
XFCE desktop settings; disable compositor

Note that the following section might nolonger be necessary…this was necessary using the Flash player 10 beta and they probably fixed it by now.  Of course, just in case you run into this problem:

To improve flash player performance by installing Flash player 10 – to make it work it’s necessary to:
> ln -s libcurl.so.4 libcurl.so.3
Personal preference:  Install gphoto to replace gkview

canon sd1000 works!

NOTE FOR PUPPY LINUX:
To get rtl8185 wireless working:
http://www.murga-linux.com/puppy/viewtopic.php?p=144470#144470

And that’s it, hope this information can help someone out!  Zenwalk Linux ran beautifully without any problems after this setup.  Amazingly the wireless worked far better in zenwalk than it did in Windows!  My friend recently got a new Dell P4 3ghz system and actually missed her old Zenwalk 866mhz computer.  I guess Windows XP immediately began giving her troubles haha..

Well, I fixed that computer up too..  But that story I’ll post next time :)