zbar icon indicating copy to clipboard operation
zbar copied to clipboard

Fix .pdf gotcha

Open za3k opened this issue 3 years ago • 7 comments

PDF does not inherently encode a resolution--it's essentially a vector format. By default, ImageMagick samples it at a tiny 72dpi resolution, so many QR codes are not read.

Default .pdf to 300dpi sample rate to fix the issue.

za3k avatar Sep 07 '22 20:09 za3k

https://stackoverflow.com/questions/73656471/use-filetoblob-in-imagemagick well i'm a bit stuck using FileToBlob() if you can offer any help.

za3k avatar Sep 09 '22 02:09 za3k

https://stackoverflow.com/questions/73656471/use-filetoblob-in-imagemagick well i'm a bit stuck using FileToBlob() if you can offer any help.

Maybe should be something like this:

void *blob = FileToBlob(filename, MagickMaxBufferExtent, &blob_length, &blob_exception);

jameshilliard avatar Sep 09 '22 03:09 jameshilliard

or maybe:

void *blob = FileToBlob(filename, MAGICK_SSIZE_MAX, &blob_length, &blob_exception);

jameshilliard avatar Sep 09 '22 03:09 jameshilliard

The second argument (extent) is not causing the issues. I started it as INT_MAX, sure, just left that out for clarity.

za3k avatar Sep 09 '22 16:09 za3k

Proposed an ImageMagick feature to help us out. If someone has thoughts on a better way to do it, feel free to comment. https://github.com/ImageMagick/ImageMagick/issues/5554

Also, went ahead and reported my issues as a bug at https://github.com/ImageMagick/ImageMagick/issues/5553. I can get it to work for an 80K file but not a 100K file (note size is like 100MB), which makes me think MAYBE it's not just a me issue.

In the meantime, I've made sure this doesn't break stdin, and I think it could be merged. It just won't work for PDFs on stdin yet.

za3k avatar Sep 09 '22 23:09 za3k

Confirmed the issue I was running into was a bug. ImageMagick has a patch, thanks ImageMagick!

I'll offer a PR that makes PDFs work on stdin too, once imagemagick's stable release includes their fix.

za3k avatar Sep 10 '22 17:09 za3k

OK, ready for submission. Apparently I was wildly wrong about how setting the density works, and I can just do it unconditionally. This is now a one-line change.

za3k avatar Sep 11 '22 02:09 za3k

Ping on this? It's a one-line change now so it seems pretty safe. You could change the default resolution to 300 or 600 if you prefer.

za3k avatar Sep 19 '22 20:09 za3k

Merged, thanks!

mchehab avatar Jan 09 '24 09:01 mchehab