Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.18k stars 1.17k forks source link

Support dpi other than 96dpi #99

Open jakeg opened 13 years ago

jakeg commented 13 years ago

I guess V8 thinks we're on a screen with 96dpi. I think wkhtmltopdf provides an option to change this to eg 300dpi instead.

To reproduce:

To (temporarily) fix:

pt = function(screen_pt) { return screen_pt / 96 * 300; // presumably? } ctx.font = pt(9) + 'pt arial';

tj commented 13 years ago

v8 doesn't have anything to do with it :p, it's in lib/context2d.js I have a few TODOs in there, more specifically the parseFont method

tnunes commented 7 years ago

Any update on this issue?

LinusU commented 5 years ago

Would love some more details on how you want this to work.

chrisspiegl commented 2 years ago

I just was trying to figure out the same thing. How to get higher DPI when creating PNG images in node.js.

I found out that when rendering image/png to base64 I could use the pngConfig setting.

myCanvas.toBuffer('image/png', {
  resolution: 74 * scale,
});

I am not yet 100% sure how exactly this works, but I found that in my use case it does increase the resolution of the image without changing the size. Something like that.

zbjornson commented 2 years ago

All the resolution setting does is set the pHYs chunk in the header. It's an ancillary chunk though and at least Chrome and Firefox ignore it. I imagine some image editing apps use it.

chrisspiegl commented 2 years ago

@zbjornson Thanks for the additional info. I am using this in the menu bar of macOS via xbar (the plugin I created shows the current download/upload speed of my internet connection).

There the resolution setting seems to help quit a lot and does the trick to increase the quality of the image displayed on my retina and non retina displays.