libqrencode icon indicating copy to clipboard operation
libqrencode copied to clipboard

Reduce SVG output size by using CSS and paths

Open Oblomov opened this issue 11 years ago • 11 comments

This commit series obtains a reduction of the output SVG size by a factor of 7, by enacting the following changes:

  • using CSS instead of tag attributes for colors and opacity; this, by itself, is enough to reduce the SVG size by about 30% to 50%, depending on whether colors have an alpha channel or not;
  • using a single path instead of a number of rects to describe the ‘foreground’ of the QR Code; this is true gainer (7× size reduction).

As a bonus, there is a patch that makes the SVG ‘dimensionless’ when the DPI is set to 0. I also needed autogen.sh to create the m4 directory, so I've included a patch to do that.

Oblomov avatar Feb 08 '14 17:02 Oblomov

Hi @Oblomov.

I like the idea with the styles instead of tag attributes. But please have a look at issue #28 . qrencode --rle does have a similar behavior as using a single path. A single path would rather be an improved version of rle (run length encoding) instead of default behavior.

thx.

d4ndo avatar Feb 08 '14 18:02 d4ndo

Good point. I will rework the patch set to change only the rle path then.

Oblomov avatar Feb 08 '14 21:02 Oblomov

Ok I've updated the patch set. Now the last commit only changes the RLE behavior, leaving the non-RLE path with a rectangle for each bit.

Oblomov avatar Feb 08 '14 21:02 Oblomov

(Rebased on current master.)

Oblomov avatar Feb 15 '14 09:02 Oblomov

Hi @Oblomov , thank you for your contribution. It seems great, but couple of tests with some tools is required. Give me some time to do it.

fukuchi avatar Feb 18 '14 13:02 fukuchi

Hello, any news about this?

The changeset has been updated on top of latest master. You may want to cherry-pick ef6fcd2, which fixes an off-by-one, regardless of the rest of the changeset.

Oblomov avatar Sep 21 '14 16:09 Oblomov

Hello @Oblomov,

I have just tested your patch. While it works very well with Inkscape, OpenOffice's Draw could not load the SVG file. Probably it means OO does not support style element but I'm not sure. Would you mind to test it?

fukuchi avatar Oct 02 '14 10:10 fukuchi

I can confirm that the SVG is not displayed correctly by:

  • LibreOffice (even the latest development branch)
  • imagemagick
  • and in general anything that depends on librsvg, which apparently doesn't handle CSS stylesheets in SVG correctly

I would say that these are bugs in librsvg/LibreOffice (that should be fixed upstream: the respective bugzillas mention related issue), but I can understand if you'd rather wait for these to be fixed before merging.

Oblomov avatar Oct 06 '14 07:10 Oblomov

@Oblomov ,

Thank you for the study. I encourage you to post the report to librsvg's community. As you concluded, let us wait for these to be fixed because librsvg is widely used.

I'll keep this request open till the issue is resolved by librsvg.

fukuchi avatar Oct 06 '14 21:10 fukuchi

Can we please already merge the "one path" patch, without using the problematic css part yet? That would help with some rendering problems (more details in the link below). https://cberhard.wordpress.com/2015/01/15/qrencode-svg-avoid-white-lines-between-pixels/

ConnyOnny avatar Jan 15 '15 23:01 ConnyOnny

I have cherry-picked @Oblomov 's single path hack to the main trunk. See b4205db. 1e91256 is not cherry-picked yet.

fukuchi avatar May 05 '15 21:05 fukuchi