Tuesday, February 11, 2014

Resizing images in batch using mogrify

Here's a quick way to resize images via shell using mogrify. It's part of ImageMagick package.

mogrify -resize 60% *.jpg

This will resize all files ending with .jpg extension to 60% of their original size.

We're only scratching the surface of what mogrify can do. Have fun exploring :)

Monday, February 3, 2014

Default Parameter Values in PHP Functions

Here's a neat way to set some default parameter values in a PHP function. This only works if a function param is passed in as associative array.

function create_profile($values) {
  if (!is_array($values)) {
    $values = array();
  }
  
  // Default key/values
  $values += array(
      'uid' => NULL,
      'username' => '',
      'mobile' => '99999999',
      'location' => 'POINT(0 0)',
      'fb_id' => ''
  );
}

The most important line is at line 7; where both arrays are merged. If the key/value pair is in the $values array, it will be ignored; else the default values will be used.