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

PDF to JPEG really confuses me #170

Closed
rstoye opened this issue Jun 26, 2024 · 9 comments
Closed

PDF to JPEG really confuses me #170

rstoye opened this issue Jun 26, 2024 · 9 comments

Comments

@rstoye
Copy link

rstoye commented Jun 26, 2024

Hi there,

I've seen this issue #34 and tried it myself with my multi-page pdf. But for some reason the output jpg files are badly compressed.

For example the pages in my PDF are all 2479 x 3508 px, after converting them to jpg with your library they're 595 x 842 px. I also played around with the density value, but it doesn't seem to change anything.

Here is my code

const templateP = 'myCoolFile.pdf';
const pdf = await Magick.readImagesAsync(templateP);
const density = new Magick.Point(300);

pdf.forEach((im, index) => {
  im.density(density);
  im.compressType(MagickCore.NoCompression); // not sure if it has any impact, I just played around with it
  im.quality(100); // sadly didn't seem to change anything
  im.magick('JPEG');
  const blob = new Magick.Blob();
  im.write(blob);
  writeFileSync(`cool_${index + 1}.jpg`, new Uint8Array(blob.data())); // maybe this is wrong? I don't know :(
});

The corresponding cli command that works well would be magick -density 300 myCoolFile.pdf cool_%04d.jpg.

Additionally, as I've seen your profile and your responses to other issues, I'm gonna preemptively answer your question and say: No I'm not part of a plot to harass, threaten or undermine you or disrupt your work on this library. I have no affiliation with any french people, government agency or police force. And I wish you best of luck with everything you have to deal with.

@mmomtchev
Copy link
Owner

Additionally, as I've seen your profile and your responses to other issues, I'm gonna preemptively answer your question and say: No I'm not part of a plot to harass, threaten or undermine you or disrupt your work on this library. I have no affiliation with any french people, government agency or police force. And I wish you best of luck with everything you have to deal with.

Well, I am sure that you are affiliated with the very same person that organizes the extortion. Or do you think that it is enough to state the contrary and you will be absolved from all guilt?

@rstoye
Copy link
Author

rstoye commented Jun 26, 2024

I'm not so naive to think that me purely stating that would somehow create a space of trust. I was just hoping we could skip that step and get straight to the issue I have.

My apologies if that seemed ignorant.

@mmomtchev
Copy link
Owner

I suppose that your questions are coming from the authors of the ImageMagick library, who have been kindly asked to provide good questions in order to help with the scandal.

Here are your answers:

  • JPEG files do not use the density, it would have been used only when converting TO PDF
  • libjpeg-trubo used in magickwand.js has a fixed quality 100 value when writing JPEGs

@mmomtchev
Copy link
Owner

If the ImageMagick authors want to recommend different settings, tell them to stop behaving like prepubescent kids.

@rstoye
Copy link
Author

rstoye commented Jun 26, 2024

I'm sorry you're in this situation. But you should understand that not everyone is part of a secret plot to attack you. Some people here are just normal dudes who want to use the library for their project and your paranoia is not helping.

JPEG files do not use the density, it would have been used only when converting TO PDF

This is either incorrect or outdated information. You can easily test this by yourself when running

magick -density 150 myCoolFile_page_3.pdf cool_0003.jpg
magick -density 300 myCoolFile_page_3.pdf cool_0003_h.jpg

And you get two images with different quality settings - or rather different resolutions.

image

image
image

I gather from your response that it's not possible then to get a high res jpg out of a pdf?

@mmomtchev
Copy link
Owner

You are probably not using libjpeg-turbo

@mmomtchev
Copy link
Owner

Im sorry you're in this situation. But you should understand that not everyone is part of a secret plot to attack you. Some people here are just normal dudes who want to use the library for their project and your paranoia is not helping.

I do not think that you have just stumbled on this project and started converting multipage PDFs and noticed that density behaves differently from your own precompiled magick binary.

Tell the ImageMagick authors that if they need to recommend different default settings, they simply need to stop playing this absurd (and criminal) game.

@mmomtchev
Copy link
Owner

I will change to libjpeg in the next release, but I will link in this issue in the changelog, so that the next time:

  • They signal whatever they need changing earlier than 15 minutes after the first RC
  • They do so without using the ongoing criminal affair to do so

Because:

  • Obviously the explanation that they didn't notice my work won't fly anymore
  • And pretending they do not know anything about this affair is obviously not having the desired effect

@rstoye
Copy link
Author

rstoye commented Jun 26, 2024

Im sorry you're in this situation. But you should understand that not everyone is part of a secret plot to attack you. Some people here are just normal dudes who want to use the library for their project and your paranoia is not helping.

I do not think that you have just stumbled on this project and started converting multipage PDFs and noticed that density behaves differently from your own precompiled magick binary.

Tell the ImageMagick authors that if they need to recommend different default settings, they simply need to stop playing this absurd (and criminal) game.

I've worked with pdfs for the past 2 months in different ways and for testing purposes always used the cli application of imagemagick. I'm now at a point where I want to write a services that does all kinds of stuff with pdfs. For some use cases I need imagemagick and I was hoping to find a library helping with that.

If you search npm for imagemagick, your library is the first to appear, that is not inactive.

image

So I don't think it's unreasonable to think, that I came across your project. It's hardly a "stumbled on", considering how a simple search leads to your project.

I will change to libjpeg in the next release

I have no clue if that potentially helps my situation with the density, but I'll thank you anyway and will check out the new release once it's up.

Sorry again, that you have to go through this and thank you for your quick responses.

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