PC Plus
204 205 206
207 208 209
210 211 212
213 214 215
216 217 218
219 220 221
222 223 224
225 226 227
228 229 230
231 232 233
234 235 236
237 238 239
240 241 242
243 244 245
246 247 248
249 250 251
252 253 254
255 256 257
258 259 260
261 262 263
264 265 266
267 268 269
270 271 272
273 274
Green Shield
DIY Dyson
Stuff to
Buy/ d/l
the Cat
Let the
Wear Black
My Old

Digg this

Add to

Submit to Reddit


PC Plus HelpDesk - issue 236

This month, Paul Grosse gives you more insight into some of the topics dealt with in HelpDesk

From the pages of HelpDesk, we look at:

  • Correcting Perspective;
  • DVD Video on Linux;
  • Command line calculator; and,
  • Random EMail Signatures.
Paul Grosse


Correcting Perspective

One of the problems you get when you want to take a picture of something flat with a shiny surface is that of getting the camera in the picture. Another serious problem is uneven lighting. You can get over these with flat objects by lighting the picture flat-on so that the illumination is even, and then take the picture from one side - hopefully, not producing too much perspective distortion - remember that the more distortion there is, the more that any inaccuracies in the lens will display themselves either in the form of barrel/pincushion distortion or chromatic aberrations (which is effectively the same thing but for different wavelengths).

If you click on the image on the right, you will get a jpeg image that you can play around with yourself. Normally, I work with png images but SuperDisc space forbids this so for the purpose of playing around, the jpeg will do. Just save it as a file and you can play around with it in your image editor. The image has already been cropped down so that it has the same aspect ratio as the original oil painting of 20" x 24" (1,000 pixels by 1,200 pixels).

So, with your image as in the picture on the right, click on the transform tool or the perspective tool - depending upon which version of the GIMP you have on your system.

If you double click on the icon, you will get the tool options dialogue box which should look something like the image on the right - this is done on a Linux system but the GIMP runs on any X-Windows system such as most UNIX systems, Windows and MacOS X as well.

If your dialogue box has an option for which transform you want, select 'Perspective'. Make sure that 'Corrective' is selected so that when we have located the grid, the final image has been corrected.

Next, click on the image you want to correct the perspective of and the transform matrix dialogue box will appear.

Move this to one side.

Like so.

One thing you will notice is that the grid goes all of the way to the corners of the image. You need to move these to the corners of the painting. If you move the mouse over the corners, the cursor will change and you can then drag each corner to the corners of the painting - doing so roughly at this stage.

When you have finished, it should look like this.

Now, zoom in by pressing the [=] key (on versions 1.x) or the [Shift][=] (ie [+]) combination.

Click on the NSEW arrow icon at the bottom right of the window and a little version of the image will appears. If you drag the mouse around inside this, you can position the main window at each corner in turn - or use the scroll bars.

Now, for each corner, position the corner of the grid accurately.
Zoom out again and you can see the full picture with the - now - correctly positioned corners.
Finally, click on the 'Transform' button and it will work out the new picture for you
Here we can see what the image looks like with the corners stretched out to the corners of the image - this was why we made the image size have the same aspect ratio as the original painting.

Note that this only works with flat objects because that is the type of object the lens is designed to take pictures of - arguably, it is only flat objects that are parallel to the film plane.

DVD Video on Linux

The problem with DVD playback on Linux is that the good people that create the DVDs don't realise that they have been locked into a system that will not let people on Linux (or other UNIX) boxes, play them back. As a result of this, the good people who code for Linux have between them provided all of us end-users (as the larger companies like to refer to their customers) with some code that will allow us to play back the DVDs that we have bought with our hard-earned cash, on our own PCs so that we can watch them ourselves.

Go to http://www.google.com/ and look for 'Linux DVD player' - just click on the preceding link to open up a new browser with the search results (if you are on line) - and you will see a number of sites.

Download and install the packages (the RPMs will install with YaST if you are using SuSE Linux - just click on the RPM file and it will be parsed and a window will open up with the option of using YaST to install it). Once you have your packages installed, you need to perform one extra task.

Linux essentially gives you the power of a mainframe operating system on a PC without it being dumbed down like Mac OS X or even worse, like Windows. As a result, the In/Out (I/O) is very good and it checks all packets. As the PC hardware is not as good at I/O as a mainframe, more time is taken to have the same level of care about the I/O as the operating system requires (ever thought that this might be a contributing factor as to why Linux and the other Unices crash less?).

So, to speed things up, you need to activate direct memory access for your DVD player. Do this with the following line...

hdparm -d1 /dev/dvd

where /dev/dvd is your player - substitute with your player if this is not the case on your machine. It could be /dev/cdrom, /dev/hdc and so on. If you are running KDE, try putting a CD into your player and pressing [Ctrl][Alt][F10] which will take you to the messages screen. You might see the system tell you what the device is called as it probes this new data storage you have just 'installed'. When you have found out, press [Ctrl][Alt][F7] to get you back to your KDE interfaces (or one of the other function keys, depending upon which flavour of Linux you use - I know that OpenBSD is different to [F7].

Finally, type 'xine' (or whatever the command for your chosen DVD player is) and watch your own movie.

Command line calculator

This is one I made earlier. The GUI calculator on Linux is quite pretty and it can do a number of things. One problem is that the interface is quite big and you need to have it all on the screen to be able to use it. Also, you don't always need a scientific calculator - I often use the slide rule that I keep next to the computer. So, I needed something that I could use with just one line of the display so that I could use the GIMP (aspect ratios and sizes) or whatever it was (the word processor for total word counts) and still see the results of the calculator on the screen at the same time.

So, I though that a command line calculator would often quite useful - especially if you have a proper number pad on your keyboard. I could move the console down so that it was almost off the screen and yet I could use it fully without having to use the mouse (press [Alt][Tab] to select the interface for typing in a new calculation). I also decided that I should use the same method of calculation as a calculator - do it in the order that it is typed in so no BODMAS.

If you've followed my Learning to Program by using Perl Masterclass in PC Plus should be able to write one yourself but I have saved you the effort. It runs quite easily and I will show you a few examples of the command line before going through the code.

calc 23*1.8+9^2

is a plain, one-liner that just gives you an answer. However

calc 9.2178+3.6 a*9.00316 a-4.12 b^c-6

is an example that uses the program's built-in memories. This allows you to do a number of calculations in one line and use the results of previous calculation as the input of others If you input just a number and then refer to that as a result, it means that you only need to type it in once so, if you were calculating the results of a complex calculation, you can just press [Up] and you get your previous calculation back - which you can then edit and the press [Enter] again to re-calculate.

The listing is fairly simple and you can see from it below (I've missed off the help part as it takes up a lot of room and isn't necessary here) that it first of all looks to see if there are any arguments passed to it and if there are, breaks them down and processes them one by one.

It looks first of all for a number, then, it looks for an operator (+-*/^) and if it finds one, it then looks for the next number. Once it gets to the end of each section of the arguments that were passed to it, it saves that as one of the variables, starting with 'a'. This can be used afterwards in the following calculations and as it is stored in its own memory (to thing of the way that calculators store things) you can use the value in memory 'a' when you are calculating what will eventually and up in 'f' - it doesn't just have to be the last one and you have a lot to go at.

26 memories are available but it is a command line calculator so we are not going to be working out too many really long calculations are we?

($progress, $step, $steps) = (0, "",

if ($#ARGV >= 0 ) {
  if ($#ARGV == 0) {
    if ($ARGV[0] =~ /^-h|--help/) {
      exit (0);
  foreach $x (@ARGV){
    $str = $x = lc($x);
    # break it up, bit by bit and
    #     calculate it
    # get a value from the string
    $error = 0;
    $n = &getval;
    if ($error != 0) {
      # jump out of loop and finish
      print "Error in $x...\n     $str\n\n";
    while (length($str) > 0) {
      # get a symbol
      if ($str =~ s"^(\+|-|\*|/|\^)"" ) {
        $fn = $1;
      } else {
        # jump out of loop and finish
        print "Error in $x...\n      $str\n\n";
      # get a value
      $m = &getval;
      if ($error != 0) {
        # jump out of loop and finish
        print "Error in $x...\n      $str\n\n";
      if      ($fn eq "+") {
        $n = $n + $m;
      } elsif ($fn eq "-") {
        $n = $n - $m;
      } elsif ($fn eq "*") {
        $n = $n * $m;
      } elsif ($fn eq "/") {
        $n = $n / $m;
      } elsif ($fn eq "^") {
        $n = $n ** $m;
    if ($error == 0) {
      # increment logging system
        if (length ($steps) >0 ) {
          # still some left so let's
          #    take the first
          $keyed = 1;
          $steps =~ s/(\w)//;
          $keyi = $1;
          $step .= $keyi;
          $args{$keyi} = $n;
        }else {
          $keyed = 0;
      # print out result
      print "$x = $n";
      if ($#ARGV > 0 ) {
        if ($keyed == 1) {
          print "  ($keyi)";
      print "\n";
    } else {
      # jump out of loop and finish
      print "Error in $x...\n     $str\n\n";
} else {
exit (0);
## subs
sub getval {
  # strip a value from the beginning
  #     of $str and return it
  # look for letters if there are any
  #     in $step
  if (length($step) > 0) {
    # previous steps exist so look for
    #     a letter at the beginning
    if ($str =~ s/^([$step])//) {
      # got one
      my $key = $1;
      my $r = $args{$key};
      return $r;
  # must start with a digit. grab it
    if ($str =~ s/^(\d+)//) {
      $v = $1;
      # look for a decimal point
      if ($str =~ s/^(\.)//) {
        # if found, get the rest
        #     of the number
        if ($str =~ s/^(\d+)//) {
          # concatenate the string
          $v .= ".".$1;
          return $v;
      } else {
        # nothing after the
        #       decimal point
        return $v;
    } else {
      $error = 1;

One thing you will notice in the code above (about a dozen lines from the end) is how it detects numbers that have decimal points. First of all, it looks for a number and then, it looks for a decimal point. If it finds one, it looks for another slice of number and then, concatenates the two strings, along with a decimal point to make the full number.

All you need to do is copy it from the SuperDisc (click here to open up a new window), extract it, make it executable and copy it to your /usr/bin or similar directory on the path. Once it is in the path, you can access it just by typing 'calc' and you don't need to type './calc' to use it.

You can see from the screen shot how unobtrusive it is.

Random EMail Signatures

Some email programs will allow you to add a standard signature to your emails. If you have ever received an email from a company, you will, most likely, have seen a large section at the end that states something along the lines that no matter how libellous the contents, it is no business of yours to go and sue them - or something along those lines.

If your email client is one of these, you will find that they do at least one of the following:

  1. allow you to have a piece of text, as defined in the email client itself, as the signature - this is usually static and can only be edited by reconfiguring the email client;
  2. allow you to use the contents of a text file as the signature - this allows there to be a central file that all of the email clients point to and makes administering the system a lot easier. For example, if the company finds that they need to change the wording of the signature, only one file needs to be edited. Once that is done, they all have the new wording.
  3. allow you to have the output of a program as the email signature - this means that you can have some flexibility. You can still use the contents of files as part of the signature but you can also have other things in there as well. I've seen some signatures boasting about uptime, workload, the current number of Firefox browsers that have been downloaded and so on - the choice is yours.

So, if a static signature is not for you, you can either have one that is different each time you write an email, or have one that is different each day. These are simple enough to do...

  • For a different signature for each email, just use the output of a program;
  • For a different one each day (you might like to say something about the day of the week in it or maybe a countdown to pay day if you have one a month), just use a file as the signature but have a program that runs on a crontab (or in the Windows scheduler - see the 27 step walk-through on page 131 of PC Plus issue 234 or the section on it on the SuperDisc) every day, before you start - possibly just after midnight.

If you look at the SuperDisc (click here to open the directory in a new browser window), you can see two directories - on for Windows and one for UNIX/Linux. If you go into the appropriate directory, you will see the files you need to copy onto your system.

One of them is a text file that contains the signatures and the other one is the program that creates the signature. Using Perl's ability to take input from the file and direct the program output to STDOUT, the email client looks at STDOUT and uses it as its input.

Signature file

The signature file is just a list of signatures separated by delimiter lines. These can be anything that is not likely to turn up in a signature but they all have to be the same as each other.

You will see that the files starts with one of these delimiting lines and has one between each quote. There is no line at the end. This makes it easy to edit the file if you have a sudden attack of creativity - just open the file in a text editor and add the line - preceded by the delimiter.

Program file

The program file just opens the signature file, finds out how many there are and selects one. It adds a bit at the beginning (to save you typing it) and draws a line of '='s above and below it. You can add another bit at the end if you want.

If you want to use this as a 'signature of the day' program, just put the code in for selecting the signature you want and then, instead of outputting the signature to STDOUT (default), open up a file and save it to that. Then, configure your email client to use that file as its signature.

Here's an example of the type of output you can have - presented generically ...


Your name here


    Noli arrogantium iniurias pati
(I'm going to clean out the guinea pigs)

any more bits here such as a disclaimer

Have fun.

Back to PC Plus Archive Index Page

- -
- -
Contact -