Archive for February, 2009

Batch converting PSD images in linux using ImageMagick

Tuesday, February 24th, 2009

I found myself wanting to batch convert a load of psd files to jpegs today, so I went about looking for a way to do it via the command line.

The tool I chose was Imagemagick. At first I was going to use the tool ‘mogrify’ but it doesnt seem to support the -flatten parameter even though it says it does in the manual… hmmm. The flatten param is needed when converting a psd because of course the psd is multi layer so if you try convert to jpeg without flattening it will generate a jpeg for each layer.

I opted for the standard ‘convert’ command with a little bash magic. The following little script will process all psd files in a folder to jpeg files. You could easily change it to pass in more parameteres etc.

#!/bin/bash

if [ -z "$1" ]
then
echo “Usage: please specify a base directory”
exit $E_NOARGS
fi

for file in $1/*; do
/usr/bin/convert -quality 80 -flatten $file ${file/psd/jpg}
done

Xdebug and PDT

Sunday, February 22nd, 2009

Today I finally got round to getting debugging working with PDT (2.0) and Xdebug 2.

It wasn’t as hard as I thought as it turned out, I had previously presumed that because I make heavy use of mod_rewrite to rewrite my urls - Xdebug would not know how to find the correct class etc to debug.

The solution was simply to create a server mapping which tells the main site url e.g http://www.mysite.com to point to /ProjectName/index.php (which is where all URLs get pointed to).

Here are the exact steps I took:

  1. First of all, you need to obviously install Xdebug, which on ubuntu is as simple as doing an apt-get install php5-xdebug.
  2. Configure your php xdebug conf file located at (for ubuntu) /etc/php5/conf.d/xdebug.ini
  3. Add the lines:
    xdebug.remote_enable=1
    xdebug.remote_host=”localhost”
    xdebug.remote_port=9000
    xdebug.remote_handler=”dbgp”
    xdebug.remote_log=”/tmp/xdebug.log”
  4. Restart apache2… then check your phpinfo() shows the correct Xdebug settings you just added (and the same for the cli using php -i | grep -i xdebug).
  5. Now for the eclipse configuration… go to Window -> Preferences -> PHP -> Debug
  6. PHP Debugger - set to XDebug
  7. Server: Add a new server by clicking on the ‘PHP Servers’ link and point the URL of the document root to your Virtual Host as setup in Apache2 e.g. http://www.mysite.co.uk.
  8. IMPORTANT - if you use mod_rewrite - add a Path Mapping  - Path on server should be your http://www.mysite.co.uk and path in workspace should be your main index.php (or whatever file you rewrite to).
  9. Set your PHP Executable to your php5 bin location (/usr/bin/php probably).
  10. You should now be golden. Go back to your project and use the Run -> Debug (F11) after selecting your index.php file in the project browser, and the debug perspective should open. Your script will be paused on the first line by default (you can change this in the debug prefs) so you can then step into your code and watch variables etc etc and other cool shit.

If you want to learn about mod_rewrite, then I suggest you RTFM :)  Its a wonderful thang…