Pages

Search This Blog

Friday, May 13, 2016

An Example of Converting PDF grid to a BMP file


Yesterday I posted a blog about converting a grid pattern into a bitmap, for use with, e.g., SuperbaKnit software. Today I am going to go through the same thing with examples, using a file that I made up.

To use this tutorial you will need:

  • A computer with Adobe Acrobat Reader and GIMP installed. I work on a Windows machine, so Mac users may need to do some translation. Having said that, both free software packages are available on Macs as well.
  • This PDF file with the patterns in it.

The pdf file has two pages with two different types of grids. The first page has dots; the second has filled squares. Each grid square represents one stitch, and is made up of many pixels wide and tall; we want to produce a bit map file with one pixel per stitch.

Here is a step-by-step process:

Open the file in Adobe Acrobat Reader.
Let's start with Pattern 1. From the menu, we choose Edit > Take a Snapshot
Using the mouse, drag and drop a rectangle around the grid you want to convert (Figure 1). For this example, I've selected a larger section of the page, so you can see the cropping later.
Figure 1. Screen shot of PDF in Adobe Acrobat Reader, showing the SnapShot region in blue

Now the image that you have selected (the part in blue) is saved in the computer Clipboard, and you can use it in other programs.

Open GIMP.
From the menu, choose File > Create > From Clipboard
You should see a copy of the part of the PDF that you just selected now in GIMP. (Figure 2)


Figure 2. Screenshot showing image now in GIMP


CROP THE IMAGE
We want to crop the image to only show the grid.
From the menu, select Tools > Transform Tools > Crop
Your cursor will now look like a little scalpel, with a cross-hair pattern. Line the cross-hair up with the corner of the grid, and select the part of the image you want to keep. When you let go, you can see where the cropped area is, and you can adjust it if you like. When you are satisfied, press ENTER, and the cropped region will be left.

Figure 3. Selection of the grid within GIMP, ready to crop

Now the greyed-out regions in Figure 3 are removed, leaving only the grid (Figure 4).


Figure 4. Screenshot showing the cropped area selected.

The next step is to change the way that the image is stored. By default, the image will be in a colour (RGB) format, with many, many colours. We want to end up with a black and white image, with only two colours (black and white). 
From the menu choose Image > Mode > Indexed
A box will pop up. Choose the line that says "Use black and white (1-bit) palette", in the middle of the box, then click on the CONVERT button at the bottom.

The changes will be comparatively minor: the edges of the circles in the image may look a bit less smooth, and you may notice some irregularities in the lines.

In the next step, we will be shrinking the image down. In my case, the image is 362 x 224. Counting the squares in the grid, we want a 12 x 8 bitmap file.

From the menu, choose Image > Scale Image. For Width, type in 12, then hit tab. In my case, I get a value for Height of 7. This isn't going to give us the right pattern. 

To the right of the boxes for Width and Height there is something that looks like a chain link. When the chain is closed, Width and Height are changed proportionately. If you click on that, it will open, allowing you to choose values that are not scaled in exactly the same way.

With the chain open, I can type in 12 for width and 8 for height. When I click on Scale, the image is rescaled to be 12 pixels wide by 8 pixels high. 

Figure 5. Image Scaling box in GIMP. Click to open the chain to the right of  Width / Height,
then type in the sizes you need.


Typing + will zoom in so you can see the new file. Each black or white square is actually a single pixel.

Figure 6. The new re-scaled file is 12 pixels wide and 8 pixels high. You will need to zoom in to see it.


Finally, we need to save the file as a BMP file, which involves Exporting it. 
From the menu, choose File > Export > 

Figure 7. Export menu, to save the file as a BMP file. You need to pick a Folder, give the file a name, and choose a file type.


Now you have completed the conversion, and your BMP file is ready to bring into SuperbaKnit.





So, this is how you can take a graphed chart such as the one above here and turn it into a bitmap file with one pixel per square, as on the right.











You can do the same thing for the other two patterns on page 1 of this PDF. 








No comments:

Post a Comment