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!





PSP to PC with RemoteJoy Lite

12 12 2008

So my final animatic is due tomorrow at 9am for storyboarding class and as per usual, I ended up procrastinating till past midnight.  Tonights form of procrastination was an attempt to capture video and audio from my PSP (fat) to my PC (at school – AMD 64bit).

Requirements: (google them) are:

  • A PSP running custom firmware ( i.e. 5.00 M33-4 )
  • RemoteJoy Lite v0.19
  • RemoteJoySDL 2007 (if you’re using 64bit)

RemoteJoyLite Installation Instructions
(THIS IS ASSUMING YOU ARE RUNNING CUSTOM FIRMWARE)

  • Extract both archives.
  • Copy the remotejoylite.prx from the RemoteJoyLite package into a folder called seplugins/ in the root of your memory stick.
  • Completely reboot your PSP, hold R-trigger to access recovery menu.  Under Plugins, enable the remotejoylite.prx plugins. Exit to XMB.
  • Connect the USB cable, the PC should recognise a new PSP Type B device.  In the install wizard browse for the appropriate libusb0.dll – I believe you can find the driver in the RemoteJoyLite package, but if you’re using a 64bit PC like I am, you’ll need to install the 64bit libusb0.dll from the RemoteJoy SDL package.
  • Then you can simply run RemoteJoyLite_en.exe! Double click it for fullscreen :)

Game compatibility seems to be sketchy, here’s my list so far:

  • Starwars Battlefront Renegade Squadron – WORKS PERFECTLY!
  • Monster Hunter Freedom 2 - WORKS PERFECTLY!
  • Prince of Persia – Rival Swords – Doesn’t work!
  • Syphon Filter – Logan’s Shadow – Works Partially (Glitchy sound or textures)
  • PSone games – Don’t seem to work..

Here’s an experimental screencapture I did of Syphon Filter – Logans Shadow (Episode 3 part 3 – Nowhere to Run) (hard difficulty)
You’ll notice the odd glitchy sound that occurs when running RemoteJoy with this game.. too bad, it would look great on a big screen :(






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