This is probably old news now but when I was googling for the margin syntax 
I found a fair few people struggling with the same issue. So I thought 
someone should put an explanation out there ready for the next person who 
seeks it out. http://www.xkcd.com/979/

The solution is actually quite simple if you stop to think about it. It's a 
case of garbage in garbage out I'm afraid. You have to ask yourself how 
many pixels per cell do you want?

Let me explain.

The data and error correction you've chosen mean that you end up with a 
version 4 QR code. That's 33 x 33 Cells. You're trying to squeeze these 
into 160 x 160 pixels. Google Charts has a limited number of options:
The largest it can go is 4 pixels per cell. Your 33 x 33 cells become 132 x 
132 pixels. That leaves (160-132)/2 = 14  pixels for your margin, 3.5 cells
Once your requested margin is greater than 3,5 cells Google Charts jumps to 
the next option.
At 3 pixels per cell your 33 x 33 cells become 99 x 99 pixels. (160-99)/2 = 
30.5  pixels for your margin, 3.5 cells 10 and a bit pixels per cell
Once you ask for 11 or more cells as your margin you're at 2 pixels per 
cell. As such if you stick to 160x160 pixels and keep increasing the size 
of the margin you'll get to 47 cells before dropping to the final option.

If instead you adjust the total dimensions of your image to accommodative a 
whole number of cells you can get different sized margins for each margin 
setting thus.

For zero margin (at 5 pixels per cell)
http://chart.apis.google.com/chart?cht=qr&chld=L|0&chs=165x165&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636<http://chart.apis.google.com/chart?cht=qr&chld=L%7C0&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636>

The to get a single cell margin on each side at the same 5 pixels per cell 
increase the total dimensions of the image by 10 pixels. (5 pixels each 
side)
http://chart.apis.google.com/chart?cht=qr&chld=L|1&chs=175x175&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636<http://chart.apis.google.com/chart?cht=qr&chld=L%7C0&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636>

and so on and so forth
http://chart.apis.google.com/chart?cht=qr&chld=L|2&chs=185x185&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636<http://chart.apis.google.com/chart?cht=qr&chld=L%7C0&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636>

If you're not sure how much data you're going to have and therefore what 
version QR code you'll be generating then you might consider ramping up 
the dimensions of the image so that you always have a high number of pixels 
per cell and the granular jumps in margin size will be less noticeable. 547 
x 547 is the maximum sized square image.

I hope that ends up helping somebody.

On Monday, 15 March 2010 10:51:18 UTC, Akademy wrote:
>
> The margin setting on the QR Code does not appear to be working as
> would be expected.
>
> Many different values produce the same margin and size of image, but
> I'd expect a different one for every value.
>
> As an example the url I'm using is:
>
> http://chart.apis.google.com/chart?cht=qr&chld=L|1&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636<http://chart.apis.google.com/chart?cht=qr&chld=L%7C1&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636>
>
> The chld part specifies the margin.
> However you get the same physical margin for units from 0 to 3, for
> units from 4 to 10 and for units from 11  (not tried higher values)
>
> This list of urls all produce the same image but each has a different
> margin setting:
> - Margin set to 0 rows: (I'd expect no margin here...)
>
> http://chart.apis.google.com/chart?cht=qr&chld=L|0&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636<http://chart.apis.google.com/chart?cht=qr&chld=L%7C0&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636>
>
> - Margin set to 1 row:
>
> http://chart.apis.google.com/chart?cht=qr&chld=L|1&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636<http://chart.apis.google.com/chart?cht=qr&chld=L%7C1&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636>
>
> - Margin set to 2 rows:
>
> http://chart.apis.google.com/chart?cht=qr&chld=L|2&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636<http://chart.apis.google.com/chart?cht=qr&chld=L%7C2&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636>
>
> - Margin set to 3 rows:
>
> http://chart.apis.google.com/chart?cht=qr&chld=L|3&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636<http://chart.apis.google.com/chart?cht=qr&chld=L%7C3&chs=160x160&chl=http%3A%2F%2Fora.ouls.ox.ac.uk%2Fobjects%2Fuuid%253A097bb75b-99ff-403f-aeba-3145cdbb7636>
>
> Is this expected or is this a bug? If it's a bug is there any scope
> for fixing?
>
> Thanks
>
> Mat
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Chart API" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-chart-api/-/gWN7BJw385EJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-chart-api?hl=en.

Reply via email to