Tuesday 10 November 2009

Tracing bitmap in Inkscape

During BOF session in MyGOSSCON 2009, Nuhaa a.k.a cawanpink representing FOSSchix.my, was presenting on how to use Inkscape to produce graphic images. After her presentation, I inform her that Inkscape has the capability to trace bitmap into vector graphic, so that if you want to scale the image, it will not become blur (when scale down) or become boxy (when scale up). I guide her the step to produce the vector image. I believe a lot of Inkscape user also did not know much about this capability. This post will explain the step.

Step:
  1. Search Google Images for the image that you want to trace. Usually you would like to trace logo to be use somewhere else. When you search for image, try to find big or medium size image. In this example, I want to search for 1Malaysia logo.





  2. Download the logo to your computer. Here is the logo that I got.





  3. Open the bitmap image in Inkscape.





  4. Press Ctrl+A to select all the image. Then select the menu Path > Trace Bitmaps





  5. Dialog option will be displayed. Select the option Colors, Stack scans and Remove background. After that, click the Update button. You will see a preview of the trace. If you are happy with the preview, click OK





  6. The vector image will be available on top of the bitmap image. If you select the logo, you can move it around. In the picture below, I move the vector image to the right.





  7. You can delete the bitmap image then move back the vector image to the canvas. After that you can do anything with the vector image. Here, I made a clone of the image, then scale it down. The image is still sharp because it is a vector.


That's all. You can save the vector image to SVG format if you want to edit it again in the future.

Happy drawing! :)

Thursday 5 November 2009

Programming in PostScript

I have found my new craze! It is programming in PostScript! :D

What is PostScript, you may ask? PostScript is a programming language optimized to print graphic and text. You can think it as a page description language, much like HTML is the document description language for the web.

It all started when Najmi posted to MyPenguin99 mailing list about the powerfulness of Python to generate a PDF file. It is called Simson Garfinkel's Notepaper Generator. Upon closer inspection, I found out that it is not the Python that is powerful, but it is the PostScript language that is powerful that you can program your paper document to look like what you want it to be.

The Python script is just a script that help you to either enable or disable a feature, change the owner of the paper, and generate the calendar to be put into the PostScript file. From the PostScript file, it is converted to PDF by using ps2pdf command line program.

Suddenly, a question pops in my head. How hard it is to hand-coded a Postscript file? I have never program a PostScript before and don't know the answer. But I'm going to find out.

Few years back when I'm an electronic engineering student, graph paper is one of my tools of the trade. Back then, when I'm running out of graph paper, I have to buy a graph paper pad with 10 sheet in it, even though I might only need a single sheet to complete my assignment.

So, to challenge myself for the PostScript programming, I'm planning to create a 1 mm by 1 mm grid that will occupy an A4 paper, with about 1 inch border from the edge of the paper. That should be easy, I think.

And actually, it is easy! I just learned PostScript in 2 days from information available on the Internet, and also found a PDF file from Adobe called "PostScript Language Tutorial & Cookbook". It contains all the command that you need to know about programming in PostScript. Search Google using the keyword "postscript tutorial".

PostScript is not hard. It is stack-based in the same manner as RPN calculator. And this is easy for me because I program Motorola microcontroller using stack-based instruction in assembly language during my university days :)

The result of the PostScript file can be viewed without having to print it out, by using GSview for Windows. You can also use Evince for Gnome or Okular for KDE. The PostScript file can be converted to PDF file
 by using PDFCreator in Windows, or ps2pdf command line in Unix/Linux/BSD.

Below are two screenshot of GSview, one viewing the A4 paper in whole, and the other zooming the paper to its width.





Get the source from the URL below. Now I can start to create my own GTD paper organizer. :D

Enjoy! :)

http://sharuzzaman.tripod.com/file/graph.ps