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

DPI changes from 72 to 25 #96

Closed
jeromegv opened this issue Oct 3, 2014 · 10 comments
Closed

DPI changes from 72 to 25 #96

jeromegv opened this issue Oct 3, 2014 · 10 comments
Labels

Comments

@jeromegv
Copy link

jeromegv commented Oct 3, 2014

Hi!

I've noticed that whenever I resize a PNG, the output file changes from 72 DPI to 25DPI

Is that normal?

Here's a picture before the resize
https://socialenterprise.s3.amazonaws.com/logos/bayani-brew-Bayani-Brew-Logo-small.png

And here's the picture after the resize
https://socialenterprise.s3.amazonaws.com/logos/thumbnail_bayani-brew-Bayani-Brew-Logo-small.png

I use:

sharp(filePath).resize(240,240).max().quality(90).toBuffer(function(err, buffer) {
fs.writeFileSync('out.jpg', buffer);
});

I do not have an issue with JPG

Thanks for your help

@lovell
Copy link
Owner

lovell commented Oct 3, 2014

Hi Jérôme,

72 pixels/inch is often used as a "default" value that can also represent "has not been set", which seems to be the case with your original image.

$ identify -verbose bayani-brew-Bayani-Brew-Logo-small.png
Image: bayani-brew-Bayani-Brew-Logo-small.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 600x603+0+0
  Resolution: 72x72
  Print size: 8.33333x8.375
  Units: Undefined
  ...

libvips defaults to 1000 pixels/m if the input image is missing the unit type.

1000 pixels/m = 10 pixels/cm = 25 pixels/inch.

$ identify -verbose thumbnail_bayani-brew-Bayani-Brew-Logo-small.png
Image: thumbnail_bayani-brew-Bayani-Brew-Logo-small.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 239x240+0+0
  Resolution: 10x10
  Print size: 23.9x24
  Units: PixelsPerCentimeter
  ...

What's the source of your original image?

@lovell lovell added the triage label Oct 3, 2014
@jeromegv
Copy link
Author

jeromegv commented Oct 3, 2014

Images are output of https://github.com/imagemin/imagemin with the optipng plugin https://github.com/imagemin/imagemin-optipng
I guess I'll need to figure out why those image are missing unit type when they get out of imagemin.

@lovell
Copy link
Owner

lovell commented Oct 3, 2014

Thanks @jeromegv. I suspect optipng is aggressively stripping away that part of the metadata.

@jcupitt, your comment in libvips' source suggests 1000 pixels/metre is a guess when unit_type is PNG_RESOLUTION_UNKNOWN. Could libvips use 2835 (72 / 2.54 * 100) instead?

@jeromegv
Copy link
Author

jeromegv commented Oct 5, 2014

Out of curiosity, when putting that 25DPI as value, does that mean that the quality of the picture has been reduced? Or it's just some arbitrary value that has no impact on picture quality?

@lovell
Copy link
Owner

lovell commented Oct 5, 2014

I believe it's an arbitrary value - at worst it might affect the resolution if printed.

jcupitt added a commit to libvips/libvips that referenced this issue Nov 4, 2014
@jcupitt
Copy link
Contributor

jcupitt commented Nov 4, 2014

Hi, I've changed the vips default to 72 dpi, as you suggested. Thanks!

@lovell
Copy link
Owner

lovell commented Nov 4, 2014

Thank you @jcupitt !

@lovell lovell closed this as completed Nov 4, 2014
@lovell
Copy link
Owner

lovell commented Nov 4, 2014

...and thank you @jeromegv for reporting this in the first place.

@lookfirst
Copy link

So, the images that I'm producing will be printed. =)

@jcupitt
Copy link
Contributor

jcupitt commented Feb 23, 2016

I used to work in the printing business. DPI is very confusing and mostly useless. A wise old print expert told me it was more helpful to think in terms of PPI, "pixels per printed inch".

Suppose you are going to be printing an area 10 inches across and you have a 3000 x 2000 pixel image. You'll get 3000 / 10 == 300 pixels for every printed inch, or 300 PPI. The rule of thumb would be: >=300 is usually enough, but you can get away with less under some circumstances. The idea is that to work out the PPI you must know how many pixels you have and what distance you intend to print over.

The DPI tag on images is missing both bits of information. It's a hint about the size the creator intended you to print at, but (confusingly) you can't calculate the resolution you'll actually get when you print at some other output size. An image tagged as "300 dpi" could have great quality or terrible quality when you print it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants