libqrencode icon indicating copy to clipboard operation
libqrencode copied to clipboard

more svg options

Open sballe73 opened this issue 10 years ago • 10 comments

Hi, I worked on a svg version that render nicely when over a picture. It works on black/white transparency and specific dot pattern.

So far, it's a python script that uses dot templates and makes a svg from the ascii output of qrcode. image It's beta version, make quite big files (1Mo for this sample) but works. How to properly share it with the qrencode community ?

sballe73 avatar May 11 '15 13:05 sballe73

Looks great.

I don't know if you are familiar with Inkscape. https://inkscape.org/ It is the number one choice for vector graphic in the open source world.

Since Inkscape plugins are written in python. I recommend you to write a plugin or expand this one: https://code.google.com/p/qr-code-plugins/wiki/Inkscape

Add some »dropdown list« , to choose a design.

<g id="Pattern">
            <rect x="4" y="4" width="1" height="1" fill="#000000" />
            <rect x="5" y="4" width="1" height="1" fill="#000000" />
            <rect x="6" y="4" width="1" height="1" fill="#000000" />

just replace the rect with your dot templates.

d4ndo avatar May 11 '15 14:05 d4ndo

I used Inkscape to create my dot templates. But now, I think to change this way qrencode -t ascii "My test sentence" | python qrsvg.py > test_sentence_qrcode.svg to something like qrencode -t fsvg1 "My test sentence" -o test_sentence_qrcode.svg where fsvg1 stands for "fancy svg model 1" So users could directly get such svg from qrencode

I plan also to work on fancy paths instead of dots. that would be fancy svg model 2.

Your idea of inkscape module is nice too. maybe easier for me :) as the module is short and easy to update.

sballe73 avatar May 11 '15 14:05 sballe73

Hello @sballe73,

Thank you for sharing your nice work. If your script is publicly available, I'll put the URL to the web page of libqrencode (and perhaps README).

fukuchi avatar May 13 '15 09:05 fukuchi

so far it's short in code and long in svg template :)

# beta version
# create a svg version of qrcode that fit more seamlessly when over a picture.
# usage qrencode -t ascii "my nice text to encode" | python qrsvg1.py > nice.svg
import sys

file_start="""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="fullSizePlaceHolder"
   height="fullSizePlaceHolder"
   id="svg4106"
   version="1.1"
   inkscape:version="0.48.4 r9939"
   sodipodi:docname="dot4.svg">
  <defs
     id="defs4108">
    <linearGradient
       id="linearGradientWhite">
      <stop
         style="stop-color:#ffffff;stop-opacity:1;"
         offset="0"
         id="stop5139" />
      <stop
         style="stop-color:#ffffff;stop-opacity:0.75;"
         offset="1"
         id="stop5141" />
    </linearGradient>
    <radialGradient
       inkscape:collect="always"
       xlink:href="#linearGradientWhite"
       id="radialGradientWhite"
       cx="5"
       cy="5"
       fx="5"
       fy="5"
       r="5"
       gradientUnits="userSpaceOnUse" />

    <linearGradient
       id="linearGradientBlack">
      <stop
         style="stop-color:#000000;stop-opacity:1;"
         offset="0"
         id="stop5139" />
      <stop
         style="stop-color:#500000;stop-opacity:0.85;"
         offset="1"
         id="stop5141" />
    </linearGradient>
    <radialGradient
       inkscape:collect="always"
       xlink:href="#linearGradientBlack"
       id="radialGradientBlack"
       cx="5"
       cy="5"
       fx="5"
       fy="5"
       r="5"
       gradientUnits="userSpaceOnUse" />
    <filter
       inkscape:collect="always" id="filterBlur" >
      <feGaussianBlur
         inkscape:collect="always"
         stdDeviation="0.2"
         id="feGaussianBlur" />
    </filter>
  </defs>
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:document-units="px"
     inkscape:current-layer="layer1"
     showgrid="false"
     inkscape:showpageshadow="false"
     inkscape:window-maximized="0" />
  <metadata
     id="metadata4111">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Calque 1"
     inkscape:groupmode="layer"
     id="layer1">"""

file_end="""</g></svg>"""

dot_background="""<path
       style="fill:#BackgroundColorPlaceHolder;fill-opacity:0.25;fill-rule:evenodd;stroke:none;filter:url(#filterBlur)"
       d="M XYPlaceHolder
m 0,7 
c 0,0 0,0 0,0
l 0,3 
l 3,0 
c 0,0 0,0 0,0 
c 0,-1.5 -1.5,-3 -3,-3 
z "
       />
    <path
       inkscape:connector-curvature="0"
       style="fill:#BackgroundColorPlaceHolder;fill-opacity:0.25;fill-rule:evenodd;stroke:none;filter:url(#filterBlur)"
       d="M XYPlaceHolder
m 7,10
c 0,0 0,0 0,0
l 3,0
l 0,-3
c 0,0 0,0 0,0 
c -1.5,0 -3,1.5 -3,3
z"
       />
    <path
       inkscape:connector-curvature="0"
       style="fill:#BackgroundColorPlaceHolder;fill-opacity:0.25;fill-rule:evenodd;stroke:none;filter:url(#filterBlur)"
       d="M XYPlaceHolder
m 10,3 
c 0,0 0,0 0,0 
l 0,-3 
l -3,0 
c 0,0 0,0 0,0 
c 0,1.5 1.5,3 3,3 
z"
       />
    <path
       inkscape:connector-curvature="0"
       style="fill:#BackgroundColorPlaceHolder;fill-opacity:0.25;fill-rule:evenodd;stroke:none;filter:url(#filterBlur)"
       d="M XYPlaceHolder
m 3,0 c 0,0 0,0 0,0 
l -3,0
l 0,3 
c 0,0 0,0 0,0 
c 1.5,0 3,-1.5 3,-3 
z"
       />"""

dot_foreground="""<path
       style="fill:url(#radialGradientDotColorPlaceHolder);stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:0.7;filter:url(#filterBlur)"
       d="M XYPlaceHolder
m 0,5  
c 0,-5 1.5,2 3,-2 
c 0.5,-1.5 -0.5,-3 2,-3  
c 5,0 -2,1.5 2,3 
c 1.5,0.5 3,-0.5 3,2  
c 0,5 -1.5,-2 -3,2 
c -0.5,1.5 0.5,3 -2,3  
c -5,0 2,-1.5 -2,-3 
c -1.5,-0.5 -3,0.5 -3,-2  
z"
       inkscape:connector-curvature="0"
       sodipodi:nodetypes="sssssssss" />"""

linesize=0
linecount=0
actualY=0
for line in sys.stdin:
    linecount+=1
    if linesize==0:
        linesize=(len(line)-17)/2
        print file_start.replace("fullSizePlaceHolder",str((linesize+2)*10),2)
    if linecount>=4 and linecount<=linesize+5:
        actualX=0
        for col in range(0,linesize+2):
            if line[7+col*2:8+col*2]=="#":
                print dot_background.replace("BackgroundColorPlaceHolder","000000",4).replace("XYPlaceHolder",str(actualX*10)+","+str(actualY*10),4)
                print dot_foreground.replace("url(#radialGradientDotColorPlaceHolder)","#000000",1).replace("XYPlaceHolder",str(actualX*10)+","+str(actualY*10),1)
            else:
                print dot_background.replace("BackgroundColorPlaceHolder","ffffff",4).replace("XYPlaceHolder",str(actualX*10)+","+str(actualY*10),4)
                print dot_foreground.replace("url(#radialGradientDotColorPlaceHolder)","#ffffff",1).replace("XYPlaceHolder",str(actualX*10)+","+str(actualY*10),1)
            actualX+=1
        actualY+=1

print file_end

sballe73 avatar May 13 '15 10:05 sballe73

Very nice work indeed, @sballe73 thanks

yphil-dev avatar May 13 '15 20:05 yphil-dev

Hi, I integrated two new options in qrenc.c The first one is the option -t fsvg1 as I wanted. The second one is an option for ascii mode : -A NUMBER or --ascii-plus NUMBER that displays in ascii not ## or two spaces but only one and the second caracter is 1 or space depending of the bit comparaison between NUMBER and the value of qrcode uint for the cell. That is not just fun but helps understand how qrcode works and make decisions when altering one in drawings. By the way, I do not see anything happen with the bit of weight 8. And I would have been nice to distinguish data from error correction with this principle.

Do you think I can branch or push somewhere here the altered version so at some point you may check and integrate modifications in ?

sballe73 avatar May 14 '15 14:05 sballe73

Better late than never :)

sballe73 avatar Sep 24 '15 18:09 sballe73

Checkout the new model of fancy codes for teeshirt printing :) teeshirt_back_magic_big

sballe73 avatar Oct 22 '15 10:10 sballe73

Nice. But to my opinion this does not fit the Unix philosophy.

bloatware is not the goal.

Why not write something that is compatible to qrencode!? To pipe to

qrencode -t SVG | fancysvg -shape round [..]

cheers

d4ndo avatar Nov 05 '15 11:11 d4ndo

Because I was not satisfied with the actual SVG option, and I thought that for lambda user it would be easier to have it with the tool than having to know that somewhere there is an addon that does it in command line.

I agree that this version is slightly bloat and I would have liked to do better, but it would take more amount of time doing something that uses for example config files to do fancy things. And I had few. And again, it is really nice to have it all in the box.

Also it is really easier to do it in the code by changing the way SVG is made than converting the SVG generated after.

So here it is... maybe more GNU philosophy than Unix one ;)

If you are able to redo my work in a better way, I will gladly make next fancy SVG following your path.

sballe73 avatar Nov 05 '15 11:11 sballe73