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

Setting --dpi has no effect on the PNG output #210

Open
pd3 opened this issue Sep 2, 2023 · 2 comments
Open

Setting --dpi has no effect on the PNG output #210

pd3 opened this issue Sep 2, 2023 · 2 comments

Comments

@pd3
Copy link

pd3 commented Sep 2, 2023

In version 4.1.1 setting the -d, --dpi option has no effect.

Steps to reproduce:

$ qrencode -V
qrencode version 4.1.1
Copyright (C) 2006-2017 Kentaro Fukuchi

$ qrencode -d 72 -t PNG -o rmme.png "test"
$ identify rmme.png 
rmme.png PNG 87x87 87x87+0+0 8-bit sRGB 290B 0.000u 0:00.000

$ qrencode -d 300 -t PNG -o rmme.png "test"
$ identify rmme.png 
rmme.png PNG 87x87 87x87+0+0 8-bit sRGB 290B 0.000u 0:00.000
@zertap
Copy link

zertap commented Dec 2, 2023

Seems to work for me

$ qrencode -V
qrencode version 4.1.1
Copyright (C) 2006-2017 Kentaro Fukuchi

$ qrencode -t PNG -d 72 -o d72.png "test"
$ qrencode -t PNG -d 300 -o d300.png "test"

$ identify -verbose d72.png | grep -A3 Geometry
  Geometry: 87x87+0+0
  Resolution: 28.34x28.34
  Print size: 3.06987x3.06987
  Units: PixelsPerCentimeter

$ identify -verbose d300.png | grep -A3 Geometry
  Geometry: 87x87+0+0
  Resolution: 118.11x118.11
  Print size: 0.736601x0.736601
  Units: PixelsPerCentimeter

https://fukuchi.org/works/qrencode/
In 3.2.0 version notes:

"--dpi" (or "-d") option has been added to qrencode. This option set DPI information in an output PNG image. (Thanks to David Dahl)

The man-page or help does not seem to be as specific, but the dpi setting is metadata only. It does not affect pixel size (geometry).

-d NUMBER, --dpi=NUMBER
specify the DPI of the generated PNG. (default=72)

If you wanted to have a bigger pixel size instead to match the dpi (like I did), you can resample it with imagick

$ convert -units PixelsPerInch -interpolate Nearest -filter point -resample 300 d72.png d300-imagick-resample.png
$ identify -verbose d300-imagick-resample.png | grep -A3 Geometry
  Geometry: 363x363+0+0
  Resolution: 118.11x118.11
  Print size: 3.07341x3.07341
  Units: PixelsPerCentimeter

This yields the same "print size" as the 72 (default) dpi setting but with bigger pixel size.
the -interpolate and -filter options are needed so the resampling does not make the image blurry.
This does have the downside that the margins are also multiplied. Setting -m 0 or -m 1 with qrencode might be desired.

You can also just specify the desired pixel size : convert -interpolate Nearest -filter point -resize 500 d72.png 500px.png
For full list of options with ImageMagick's -resize see https://imagemagick.org/script/command-line-options.php#resize


So, this is not really a bug but a feature request for setting the desired pixel size and scaling the qr-code accordingly as I see it.

@pd3
Copy link
Author

pd3 commented Dec 4, 2023

Mmm, okay. I will not question the usefulness of the --dpi option, but the only thing that ever mattered to me was the resolution of an image. That would be a useful addition!

Thank you for offering a workaround via imagemagick.

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