9

I have a QR code in jpg format with low quality and I need to convert it to SVG with perfect squares.

enter image description here

I tried Trace Bitmap with Inkscape using Edge detection and all the other options, but I can't find the right mix of settings to get perfect squares result. Is this even possible?

enter image description here

2
  • 3
    Is there a reason you're trying to edit an existing QR code rather than using a service to generate a new higher resolution version?
    – AndrewH
    Commented Sep 29, 2023 at 15:22
  • my client provided me their qr code but as jpg, so i decided to convert it to svg. i found a way, i just create a new document like in this answer then i paste the image and align it to the grid and then export as svg. then in gimp i just increase the exposure and the black levels to get rid of the light gray tints Commented Sep 29, 2023 at 15:25

5 Answers 5

17
  1. Open the image in GIMP, and crop it to the edge of the QR code as close as you can get.

  2. Next you need to scale the image so that 1 square = 1 pixel. There are 33 x 33 squares (I counted them)

  3. Do Image > Scale Image > type 33px as the size, set Interpolation None, and scale it.

  4. Do Image > Scale Image > type 330px as the size, set Interpolation None, and scale it up.

  5. Select All, copy

  6. Paste into Inkscape

  7. Do the bitmap trace, using the default settings. (Brightness cutoff)

EDIT: and don't forget to delete the raster image after tracing!

Here's the result zoomed in a bit

enter image description here

7
  • Thank you for your help! That's also an interesting approach. What do you think about my approach I also posted an answer, is it quicker? Commented Sep 29, 2023 at 15:44
  • @HarryMcKenzie Hmmm . . . sure, if it works then it's fine. Perhaps you can time it. However, this method will allow you to create an SVG that is pixel perfect, which you can then export as a perfect PNG from Inkscape using the same method as in my other answer.
    – Billy Kerr
    Commented Sep 29, 2023 at 15:49
  • I'm just confused that after I exported it to SVG from the method in my answer, and then try opening the svg again, it's still showing my pasted image aligned to the grid, instead of a truly black and white svg, but my result as png is pixel perfect How come it did not convert it to a real svg? Commented Sep 29, 2023 at 15:58
  • 1
    @HarryMcKenzie You need to bitmap trace an image to create an actual SVG. There is no direct conversion of raster to vector. SVGs can also contain raster images. There is also a possibility you forgot to delete the raster image. After tracing, you need to delete the raster image otherwise it will be included inside the SVG.
    – Billy Kerr
    Commented Sep 29, 2023 at 16:10
  • 2
    @HarryMcKenzie Yeah, lots of people think if they just put a raster image inside an SVG, it will turn it into vector if they then save it as an SVG. It's a fairly common (but incorrect) assumption, so don't feel too bad.
    – Billy Kerr
    Commented Sep 29, 2023 at 16:47
9

I would just use a service like Adobe Express or another QR generator to remake the QR code. With Adobe Express, you can export the QR code as a SVG file.

8
  • 1
    Inkscape even has a built-in QR-code generator: 'Extensions → Render → Barcode / QR Code → QR Code...'
    – Xrott
    Commented Sep 29, 2023 at 15:26
  • unfortunately this will not produce the same qr code as my client's orig because this service uses more "data" to encode. the one from my client only produced a 33x33 qr. this one produces a larger one and not suitable for smaller prints. notice when you scan this one it produces "facebook.com/profile.php?id=61550679391101&mibextid=LQQJ4d" but you can't generate the same qr with adobe express Commented Sep 29, 2023 at 15:27
  • 1
    i tried to find a service that would produce the same qr but i couldn't find any so that's why i had to resort to find a way to convert it to svg. If you can recommend a site that can create exactly this qr for free with lesser data, please let me know :) the site qr-code-generator.com can generate this exact QR but unfortunately i can't download the SVG for free Commented Sep 29, 2023 at 15:37
  • 3
    @HarryMcKenzie -- there's absolutely nothing special about that QR code, there are plenty of services that can create it with equal ease. The very first one that came up on googling for it does it just as well: qrplanet.com/qr-code-generator-svg --and it's free. Don't worry that the code doesn't look exactly the same as your JPG, as long as you can read it back (eg. with a simple mobile phone app), it works. QRs can have different error tolerance settings and they will produce different but equally valid codes.
    – Gábor
    Commented Oct 1, 2023 at 16:53
  • 1
    @HarryMcKenzie -- You're free to select from the various error correction levels, in your particular case it's level L. The size will be the same as your original. But even if the size is the same, the code itself might look different and still encode the same payload. That's what I spoke about when I said it didn't matter.
    – Gábor
    Commented Oct 2, 2023 at 13:39
4

If you do not care about reproducing that exact image but just a QR code containing the same information, you can use simple QR code tools to decode and directly re-encode into a crisp QR code.

On any Unix with the right tools installed, this is a one-liner:

zbarimg input.png | qrencode -m 0 -t SVG -o output.svg

(-m 0 suppresses the margins.)

4

You are wasting your time and the client's money in labor costs, it's a gosh darn QR code.

The QR code merely resolves to https://www.facebook.com/profile.php?id=61550679391101&mibextid=LQQJ4d

Go to https://www.qr-code-generator.com/, click URL, paste your text, and download however you please.

Here is the PNG result:

enter image description here

1
  • 1
    yes i know i already resolved it with the command line utility qrencode. and it was also an interesting learning experience, because image editing is fun :D Commented Oct 3, 2023 at 0:57
1

Create a new document in Inkscape and go to File > Document Properties then set the format to px and set the width and height to the number of squares in the QR plus the padding. In my case it has 33x33 squares plus 2 padding on each side so that gives 37x37. Go to the Grid tab and create a grid with 1px as major lines. Then paste the jpg and align the image to the grid and export it as SVG. This may create some grayish areas but you can easily get rid of them in Gimp using Colors > Exposure and increasing the Exposure and Black Levels. I ended up with pixel perfect QR.

enter image description here

1
  • 1
    I just realized this will only create a pixel-perfect png file but not the vectorized version svg. Commented Sep 29, 2023 at 16:44

Your Answer

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

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