1

I'm trying to resize a vector graphic QR code in Gimp but it always creates an additional color in it gray. I want it to be pure black and white with perfect corners like in the original image on the left.

enter image description here

I tried opening the vector graphic (svg) with Inkscape and exporting a png at 200x200 px but I still get the same grayish result above. I also tried setting the DPI to a full integer like 20, instead of 19.81, which resulted in 202x202 but still same problem.

enter image description here

Thanks to Rafael for solving my problem, so I know now I have to count the number of squares in my QR which was 57 in my case and I choose the number of pixels per square, say 4px, that makes 228x228 the proper "minimum" size. Now I just wonder why Inkscape would still add light gray "shadows" to the result.

enter image description here

3
  • 1
    Use a vector editor.. such as Inkscape. Gimp is a raster editor. It is possible to pound in a nail with a pair of pliers... but you generally get better, more efficient result if you actually use a hammer, the proper tool.
    – Scott
    Sep 28 at 9:01
  • @Scott thank you for the response! I did try open with inkscape and then I did a File > Export to 200x200 pixel from the vector graphic and I still see the grayish result. Is there another way I should do it? I didn't see any "scale" option in inkscape Sep 28 at 9:32
  • 1
    @HarryMcKenzie It is possible to do this entirely in Inkscape. I've added an answer now covering how to do it, and what the problem is. Basically the image needs to be pixel perfect (currently it isn't).
    – Billy Kerr
    Sep 28 at 15:38

2 Answers 2

2

The SVG isn't pixel perfect. That's the problem.

Use Inkscape for this, for creating the QR code using the built-in QR Code extension, and for exporting as PNG at the size you need. Forget GIMP for the time being.

  1. Create a new document in Inkscape, and in the Document Properties set the sizes to pixels, and the size to 109px x 109px

  2. In the document properties also set up a 1px grid so you can check everything is lined up, just in case (not necessary though, as it should work if you follow all the instructions).

  3. Click Extensions > Render > Barcode/QR Code > QR Code. Type in your link in the text box at the top, set the size in unit squares to 101x101, make sure to set the square size to 1px, and set the square smoothing to 0.00. Note: The finished QR code will be 109x109 including a 4px white border all round.

  4. Generate the QR code by clicking Apply.

  5. Zoom into the image close to a corner. You should see something like this showing all the edges aligned to the pixel grid.

enter image description here

  1. To export, in the export panel, under the Page tab, set the size you wish to export by multiplying the existing size (109) by an integer. In this example I have multiplied by 10, giving 1090. If you want an image around 200px, then you would need to multiply by 2, giving 218 pixels. It must always be an integer, or everything will be messed up. Make sure you are exporting as PNG, obviously.

enter image description here

  1. Hit the Export button.

  2. You can check the PNG image in GIMP. It will be pixel perfect without any grey pixels. It is possible to scale this in GIMP too once you have a pixel perfect image, but you must remember to set Interpolation to none, and you must also enlarge/reduce by multiplying or dividing by an integer (same as in Inkscape).

Here's an example I created using the above technique, solely in Inkscape. You can check it by opening in GIMP and zoom in.

6
  • wow now it's perfect! thank you very much! oh but the svg was generated using qr.io so their software isnt perfect? Sep 29 at 0:50
  • btw what do you mean by "svg is not pixel perfect"? i still used the same svg and employed your method to create a px document. since my qr is 53x53 squares i created a 57x57 px document that includes the 2px padding on both sides. then i scaled my svg to perfectly align to the grid and then exported it. it works perfect now! thank you so much! but it would still be interesting if you could expound on the "not pixel perfect" issue since i didn't have any issue with it. Sep 29 at 2:41
  • aaah ok i see what you meant by pixel perfect, i zoomed into inkscape document and i can see it doesn't 100% align there is super super super slight misalignment, okay so that is what still causes this super super light "tint". good to know! so their software was not perfect. can you recommend a website that creates pixel perfect qr code? the built-in one in inkscape only supports links. i didnt see any option for vcard or other types of data. Sep 29 at 2:50
  • 1
    Yeah, when I said "not pixel perfect" it means the pixels of the design don't align exactly with the pixel grid. Sorry I don't know if there are other extensions available for Inkscape specifically, although it might be possible to perhaps align something created elsewhere to the grid, but it might take some manual effort.
    – Billy Kerr
    Sep 29 at 5:07
  • 1
    oh yes you are correct, i think there is just a formatting or syntax to input the data so it detects it as a certain format like vcard. thanks for the info :) Sep 29 at 13:06
1

If it is a vector, resize it as a vector.

If it is a raster image, you need to use exact multiples. But you need to consider some more things.

If your image is let's say 500x500px you can only resample it as 250x250, Or you can scale it up to 1000x1000px or 1500x1500px.

Only use the nearest neighbor method. If you need to assemble it on let's say a banner, resample it separately and then copy and paste it into your canvas.

Scaling up to a bigger size could handle a small level of imperfection, Let's say you could scale it up to 1900 instead of 2000, but for smaller sizes, you need to count and measure the squares.

Each QR has a specific number of squares, plus the safe area is a multiple of those squares. Count them before reaching a smaller number than that.

One "rule" is that you do not "force" your QR to be the minimum size. So each square should NOT be only 1 px, but let's say a minimum of 3-4 pixels each.


An additional note based on the comments.

Although vector files are not made by pixels, some view modes are based on a grid to preview the alignment when exported to a raster file.

So if the shape is not perfectly aligned with that "invisible" grid, if the origin of the shape is not perfectly aligned with the origin of the file it might render that small "alias" meaning that the black squares start to "tint" the next pixel.

One way to avoid it is to resize the canvas to perfectly match the dimensions you need, and also the shape, and align them to fit each other.


And a workaround would be to export it as it is and then apply some level adjustment, or change it to black-and-white color mode.

5
  • oh ok i get what you mean with the counting squares it makes sense that i have to make sure the squares fit perfectly in the pixel width i choose. Sep 28 at 13:01
  • nice it works. i counted the squares to 57. so that means if i choose 4 pixel per square i get 228 pixel width, i exported it to 228x228 and now it works without any gray zone! thank you soo much! Sep 28 at 13:03
  • i have one final question i hope you can address this one... why would Inkscape still add super light gray "shadows" to the result snipboard.io/r4op62.jpg Sep 28 at 13:12
  • 1
    I added a note. Let's see if that helps you.
    – Rafael
    Sep 28 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.