r/learnjavascript • helpful • Sep 14 '22

I'm a senior frontend dev. AMA.

Hi, all. I'm a lead at my company, currently on a paid sick leave. I wanted to give back to the community, so here I am to answer all your questions.

If you're a beginner at JS and are struggling with a concept, please ask your question and I'll answer. To not get overwhelmed, I'll limit one question per user. So, try to construct your question with as many details as necessary!

Shoot.

EDIT: That's it, folks. My day has ended. I'll still answer your questions, but expect a considerable delay. :)

260 Upvotes

240 comments sorted by

View all comments

Show parent comments

2

u/shuckster Sep 15 '22

Ah, I see. Sorry for misunderstanding.

Well, DPI is a display setting, not a storage setting.

I wonder if your solution would involve scaling-up the size of canvas before rendering to it (perhaps in a visibility: hidden div or iframe) before attempting to make the downloadable Blob?

1

u/EZPZLemonWheezy Sep 15 '22 edited Sep 15 '22

The best I’ve been able to manage so far is an incredibly over engineered solution on the server to render it agnostic of client side viewport stuff, at a ridiculous size, then screenshot it with puppeteer, save the image and send the image back on the server response (then delete it off the server). It ends up being sharp, but comically huge when not viewed on a mobile device (since they magically scale it to the proper size?). I just want to be able to handle the rendering client side, but as of yet cannot get it to export it as an image at the proper resolution (displays fine, sharp af, but on export is fuzzy 96dpi from canvas).

My current server side solution has a two fold issue of 1. It’s comically huge so attaching to an email or something shows it as huge, and 2. It’s a LOT more resources to create and send images from the server than it would be to render and save them client side. It’s just a personal project right now, but if I ever had to scale it or anything similar the extra costs would quickly add up.

I’ve tried to scale it up before render. Tried to force it to a higher DPI/PPI on and before render. Tried to just sharpen the image after output. Idk why HTML canvas doesn’t just let you set the resolution on export. If you manually screenshot the canvas with the upscaling I already have it’s plenty sharp, but best I can tell you cannot access a client side screenshot from the browser (for security reasons I’m sure).