Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colab #50

Closed
qo4on opened this issue Jan 26, 2023 · 15 comments
Closed

Colab #50

qo4on opened this issue Jan 26, 2023 · 15 comments

Comments

@qo4on
Copy link

qo4on commented Jan 26, 2023

Can I run it in Colab?

@aruZeta
Copy link
Owner

aruZeta commented Jan 30, 2023

I'm sorry I have never used Colab nor I know what it's used for, so I don't know.

@qo4on
Copy link
Author

qo4on commented Jan 30, 2023

Unfortunately, I never used Nim.
Probably Colab should work, at least it shows the version of the installed Nim:

!pip install git+https://github.com/demotomohiro/nim4colab.git
%load_ext nim4colab
%%nimc
echo "Nim version is ", NimVersion

Installing Nim stable
done
Hint: used config file '/root/nim-stable/nim/config/nim.cfg' [Conf]
Hint: used config file '/root/nim-stable/nim/config/config.nims' [Conf]
.........................................................
CC: nim-stable/nim/lib/std/private/digitsutils.nim
CC: nim-stable/nim/lib/system/dollars.nim
CC: nim-stable/nim/lib/system/io.nim
CC: nim-stable/nim/lib/system.nim
CC: code.nim
Hint:  [Link]
Hint: gc: refc; opt: none (DEBUG BUILD, `-d:release` generates faster code)
26647 lines; 1.341s; 31.695MiB peakmem; proj: /root/code.nim; out: /root/code [SuccessX]
Hint: /root/code  [Exec]
Nim version is 1.6.11

But I don't know how to run nimble install, it returns the error undeclared identifier: 'nimble':

%%nimc
nimble install qrgen

Hint: used config file '/root/nim-stable/nim/config/nim.cfg' [Conf]
Hint: used config file '/root/nim-stable/nim/config/config.nims' [Conf]
.........................................................
/root/code.nim(1, 1) Error: undeclared identifier: 'nimble'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (3, 2): 'File' [type declared in /root/nim-stable/nim/lib/system/io.nim(21, 3)]
 (3, 2): 'nimvm' [let declared in /root/nim-stable/nim/lib/system.nim(529, 5)]

@qo4on
Copy link
Author

qo4on commented Jan 30, 2023

I managed to run it

%nimble -y install qrgen
%%nimc
import QRgen
let myQR = newQR("https://github.com/aruZeta/QRgen")
myQR.printTerminal

image

@qo4on
Copy link
Author

qo4on commented Jan 30, 2023

Just wondering, have you tested the reliability of qr codes with pictures? What parameters should be used to create a qr code so that it works 100% of the time with all phones?

myQR.renderImg("#1d2021","#98971a",100,100,25,img=readImage("QRgen-logo.png"))

@aruZeta
Copy link
Owner

aruZeta commented Jan 30, 2023

The problem is not the phone but the QR scaner used, depending on the scanner it may or may not read complicated QR codes, like ones with rounded corners, spacing or even images.

Also the image should not be a problem since it calculates it's max size depending on the selected ECC level, so the amount of broken bits can be recovered.

@qo4on
Copy link
Author

qo4on commented Jan 30, 2023

For some reason printSvg doesn't work. Is there any way to save the svg to a file?

import QRgen
let myQR = newQR("https://github.com/aruZeta/QRgen")
myQR.printSvg

/root/code.nim(3, 5) Error: expression 'printSvg(myQR, "#ffffff", "#000000", 0, 0, 0, "qrCode", "", "",
         genDefaultCoords(myQR), false)' is of type 'string' and has to be used (or discarded); start of expression here: /root/code.nim(2, 1)

@aruZeta
Copy link
Owner

aruZeta commented Jan 30, 2023

Yes, printSvg returns you a string, so you just need to pipe it into a file, take a look to the tests file tests/testQRGen.nim, here is an example:

  let qr = newQR("https://github.com/aruZeta/QRgen")
  writeFile(
    "build" / "testingSvg.svg",
    qr.printSvg
  )

@qo4on
Copy link
Author

qo4on commented Jan 31, 2023

How do you get this qr code? I would like to remove the dots around the logo as in your example.
image

!wget -O logo.svg https://upload.wikimedia.org/wikipedia/commons/b/b8/YouTube_play_button_icon_%282013%E2%80%932017%29.svg

%%nimc
import QRgen
let qr = newQR("https://github.com/aruZeta/QRgen", ecLevel=qrECH)
writeFile("testingSvg.svg", qr.printSvg("#1d2021", "#98971a", 100, 100, 25, svgImg=readFile("logo.svg")))

testingSvg

@aruZeta
Copy link
Owner

aruZeta commented Feb 1, 2023

Yes, that's intended behaviour, to avoid it you would just add a non-transparent background to your image, but oh well there should be a way to force a square to be drawn behind it.

@qo4on
Copy link
Author

qo4on commented Feb 1, 2023

Do you mean that all the svg need to be specially edited by placing them on an non-transparent background rectangle of the same color as the background of the qr code? Also, the size of this rectangle must be manually adjusted for each qr code so that its borders do not partially overlap the dots of the qr code itself and do not divide them into two parts, right?

@aruZeta
Copy link
Owner

aruZeta commented Feb 1, 2023

The current implementation does not offer a way to force a background for transparent images.
About the size, you don't need to mind it since it's actually calculated to fit perfectly (and you can even force an x,y position and a width,height, although not recommended since it could mess up the QR code and make it unreadable unless you test it or know what you're doing).

@qo4on
Copy link
Author

qo4on commented Feb 1, 2023

Is there any reason why you can't get a qr code like this without editing the svg and placing it on an opaque background?
image

@aruZeta
Copy link
Owner

aruZeta commented Feb 1, 2023

As I said it's not that there is a reason of why you can't force a layer between the QR and the image, so as in a way to act as the background of the image, but that it's just not implemented.

It shouldn't be a difficult task, but I will try it whenever I have the time and energy to do it.

@qo4on
Copy link
Author

qo4on commented Feb 1, 2023

I see, thank you. Anyway, you did a very good job. And it would be absolutely perfect if you manage to add a way to force a background for transparent images.

@qo4on qo4on closed this as completed Feb 1, 2023
@aruZeta
Copy link
Owner

aruZeta commented Feb 1, 2023

Yeah it's something that's missing from the library, but I'm very sorry I don't have any time atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants