def svg(self, file, scale=1, module_color='#000', background=None, quiet_zone=4, xmldecl=True, svgns=True, title=None, svgclass='pyqrcode', lineclass='pyqrline', omithw=False, debug=False): """This method writes the QR code out as an SVG document. The code is drawn by drawing only the modules corresponding to a 1. They are drawn using a line, such that contiguous modules in a row are drawn with a single line. The *file* parameter is used to specify where to write the document to. It can either be a writable stream or a file path. The *scale* parameter sets how large to draw a single module. By default one pixel is used to draw a single module. This may make the code too small to be read efficiently. Increasing the scale will make the code larger. Unlike the png() method, this method will accept fractional scales (e.g. 2.5). Note, three things are done to make the code more appropriate for embedding in a HTML document. The "white" part of the code is actually transparent. The code itself has a class given by *svgclass* parameter. The path making up the QR code uses the class set using the *lineclass*. These should make the code easier to style using CSS. By default the output of this function is a complete SVG document. If only the code itself is desired, set the *xmldecl* to false. This will result in a fragment that contains only the "drawn" portion of the code. Likewise, you can set the *title* of the document. The SVG name space attribute can be suppressed by setting *svgns* to False. When True the *omithw* indicates if width and height attributes should be omitted. If these attributes are omitted, a ``viewBox`` attribute will be added to the document. You can also set the colors directly using the *module_color* and *background* parameters. The *module_color* parameter sets what color to use for the data modules (the black part on most QR codes). The *background* parameter sets what color to use for the background (the white part on most QR codes). The parameters can be set to any valid SVG or HTML color. If the background is set to None, then no background will be drawn, i.e. the background will be transparent. Note, many color combinations are unreadable by scanners, so be careful. The *quiet_zone* parameter sets how wide the quiet zone around the code should be. According to the standard this should be 4 modules. It is left settable because such a wide quiet zone is unnecessary in many applications where the QR code is not being printed. Example: >>> code = pyqrcode.create('Hello. Uhh, can we have your liver?') >>> code.svg('live-organ-transplants.svg', 3.6) >>> code.svg('live-organ-transplants.svg', scale=4, module_color='brown', background='0xFFFFFF') """ builder._svg(self.code, self.version, file, scale=scale, module_color=module_color, background=background, quiet_zone=quiet_zone, xmldecl=xmldecl, svgns=svgns, title=title, svgclass=svgclass, lineclass=lineclass, omithw=omithw, debug=debug)
def svg(self, file, scale=1, module_color='#000', background=None, quiet_zone=4, xmldecl=True, svgns=True, title=None, svgclass='pyqrcode', lineclass='pyqrline', omithw=False, debug=False): """这个实例方法是把二维码写成一种 SVG 文档格式。 二维码只会把数据块绘制成1。数据块都会用一行来绘制, 例如一行中的连续数据块都会绘制在单行里。 其中 *file* 参数是用来描述存储文件位置用的。 即可以是可写的流数据,也可以是一个文件路径。 其中 *scale* 参数是设置单个数据块要绘制多大。 默认值是用1个像素绘制一个数据块。也许会让二维码太小无法有效读取。 增加参数值会让二维码变大。与 `png()` 方法不一样, 这个方法回接受分数标量值(例如,2.5)。 注意,有三件事实现后能建立适合嵌入到 HTML 文档中的二维码。 那就是二维码的 "白色" 部分要完全透明。 二维码本身有一个已知类 *svgclass* 参数。 组成二维码的路径使用这个类设置,使用的是 *lineclass* 参数。 这些因素让建立二维码更容易使用 CSS 风格。 这个方法的默认输出结果是一个含有完整的 SVG 的 XML 文档。 如果只想要二维码本身的话,把 *xmldecl* 参数值设置成 `False` 即可。 这样会形成一个含有只绘制二维码部分的 SVG 片段。 同时,你可以设置 *title* 参数给文档提供页面抬头内容。 对于 SVG 名字空间属性可以通过设置 *svgns* 参数值为 `False` 来 实现不显示二维码图形,只显示 XML 文档树内容。 其中 *omithw* 参数值设置成 `True` 会说明要忽略宽高属性。 那么会有一项 ``viewBox`` 属性增加到 XML 文档中,效果就是 页面中有一个类似全屏的二维码图像了。 你也可以直接设置颜色,使用 *module_color* 和 *background* 参数。 其中 *module_color* 参数是设置数据块要使用的颜色(大部分都是黑色)。 其中 *background* 参数是设置背景色(大部分都是白色)。 这两个参数可以设置成任何一种合法的 SVG 或 HTML 安全色。 如果背景参数值设置成 `None` 的话,不会绘制背景色,例如背景色是透明的。 注意,许多颜色组合都不会被二维码扫描器读取,所以用色要谨慎。 其中 *quiet_zone* 参数是设置无噪点区域宽应该是多大。 根据二维码标准这个参数值应该是4个数据卡宽。保留成可设置是因为许多应用 程序中不需要无噪点区域宽,因为很少会打印二维码。 Example: >>> code = pyqrcode.create('Hello. Uhh, can we have your liver?') >>> code.svg('live-organ-transplants.svg', 3.6) >>> code.svg('live-organ-transplants.svg', scale=4, module_color='brown', background='0xFFFFFF') """ builder._svg(self.code, self.version, file, scale=scale, module_color=module_color, background=background, quiet_zone=quiet_zone, xmldecl=xmldecl, svgns=svgns, title=title, svgclass=svgclass, lineclass=lineclass, omithw=omithw, debug=debug)
def svg(self, file, scale=1, module_color='#000000', background=None): """This method writes the QR code out as an SVG document. The code is drawn by drawing only the modules corresponding to a 1. They are drawn using a line, such that contiguous modules in a row are drawn with a single line. The *file* parameter is used to specify where to write the document to. It can either be a writable stream or a file path. The *scale* parameter sets how large to draw a single module. By default one pixel is used to draw a single module. This may make the code too small to be read efficiently. Increasing the scale will make the code larger. Unlike the png() method, this method will accept fractional scales (e.g. 2.5). Note, three things are done to make the code more appropriate for embedding in a HTML document. The "white" part of the code is actually transparent. The code itself has a class of "pyqrcode". The lines making up the QR code have a class "pyqrline". These should make the code easier to style using CSS. You can also set the colors directly using the *module_color* and *background* parameters. The *module_color* parameter sets what color to use for the data modules (the black part on most QR codes). The *background* parameter sets what color to use for the background (the white part on most QR codes). The parameters can be set to any valid SVG or HTML color. If the background is set to None, then no background will be drawn, i.e. the background will be transparent. Note, many color combinations are unreadable by scanners, so be careful. Example: >>> code = pyqrcode.create('Hello. Uhh, can we have your liver?') >>> code.svg('live-organ-transplants.svg', 3.6) >>> code.svg('live-organ-transplants.svg', scale=4, module_color='brown', background='0xFFFFFF') """ builder._svg(self.code, self.version, file, scale, module_color, background)