2008-03-19

Poor Man's Which Command For Windows Cmd.exe

The Windows Command Processor (cmd.exe) doesn't seem to have an equivalent to a Unix shell's which command to find the directory in the PATH variable of a given executable. Here's a poor man's version using the for command:

>for /F %i in ("notepad.exe") do @echo %~$PATH:i
C:\WINDOWS\system32\notepad.exe
>for /F %i in ("gawk.exe") do @echo %~$PATH:i
C:\Program Files\GnuWin32\bin\gawk.exe

20-Mar-2008: Added as a macro using doskey:

>doskey which=for %i in ("$1") do @echo %~$PATH:i

2008-03-15

Making ID Photos with GIMP

You can make ID photos cheaply using GIMP:

  1. Take a head-and-shoulders picture with your digital camera.
  2. Load or paste the image into GIMP.
  3. Rotate the image, if necessary, to a portrait orientation using menu item Image / Transform / Rotate 90 ….
  4. Shrink the image to one quarter the original size using menu item Image / Scale Image. You have to calculate the required pixel size because the Scale Image doesn't have a "shrink by half" function.
  5. Create a new image with the dimensions of the original image, in landscape orientation.
  6. Select menu item Image / Configure Grid and set the spacing so that it matches the size of your shrunk image. The idea is to have a grid as per ASCII art below:
    +--+--+--+--+
    |  |  |  |  |
    +--+--+--+--+
    |  |  |  |  |
    +--+--+--+--+
    
  7. Select menu item View / Snap to Grid and View / Show Grid.
  8. Copy and paste your shrunk image into the new image. You should be able to fit 8 images in one picture. Use the grid to help you position the images in each cell. Positioning all images in the grid's cells also makes it easier to cut the photos after they have been printed.

My camera takes 3072 x 2304 pixel images (or 6:4.5 ratio), so if I use 15cm x 10cm (6:4 ratio) paper, the images on the left and right edges would be cropped unless I further shrink the images by 5%.

2008-03-11

How to Extend Image with GIMP

If you have an image with a plain background that is too short or narrow, here's how you can extend it using GIMP 2.x. Note that extending an image is not the same as stretching an image using a transformation; important elements in the image are not distorted, just moved (see ASCII art below).

+----+     +------+
|A  B| ==> |A    B|
+----+     +------+
  1. Open the image file.
  2. Select menu item Image / Canvas.
  3. In Set Image Canvas Size dialog, uncheck the link between Width and Height, enter the required dimensions, then press the Resize button.
  4. Select menu item Layer / Layer to Image Size. You have to extend the background layer because you cannot see any part of the image beyond the background layer's boundaries.
  5. Use Rectangle Select Tool, select area to move, then copy selection to clipboard.
  6. Paste selection into image (which creates a Floating Selection in the Layers dialog).
  7. Move the selection to the required position in the layer. If you want to precisely place the selection, you should zoom in and use the cursor keys.
  8. When you are satisfied with the position of the selection, use Layer / Anchor Layer to put it back into the background layer.
  9. Use the Color Picker Tool to select a colour, then use a Pencil Tool or Paintbrush Tool to touch up the background.

Note that you can only move the selection after you have created a Floating Selection, which confused me initially because I thought that just copying a selection would give me an object to move.