Readit News logoReadit News
seedgou commented on Show HN: Make your PDF look scanned in browser   lookscanned.io... · Posted by u/seedgou
moralestapia · 4 years ago
Here's a very naive blur implementation (which is your most expensive operation there),

https://codepen.io/almosnow/pen/abEXBZP?editors=0011

(at the end of the blur pass it prints the elapsed time to the console)

You're right, it does get kind of slow at 2x, but not that slow, on my laptop it takes around 1 sec/page, while on your site takes 20-30 secs/page. Also, my very naive code does not take into account "warming up" and some other code optimizations to make the blur much faster, you could easily get it down to 100ms/page, I'm sure!

Best luck!

seedgou · 4 years ago
Oh! You mean the scanning speed. I thought you was talking about the original PDF preview. For now, scanning is using emscriptened ImageMagick Wasm. Due to the translation from C++ to Wasm, the scanning speed is very slow. Maybe re-writing blur, rotate and noise algorithm will speed up the scanning.
seedgou commented on Show HN: Make your PDF look scanned in browser   lookscanned.io... · Posted by u/seedgou
moralestapia · 4 years ago
That could be the case yes, still I feel it should be better, let me do a quick test as I have some spare time.
seedgou · 4 years ago
The rendering logic is in `src/utils/pdf/renderPage.ts` and has only 26 lines.
seedgou commented on Show HN: Make your PDF look scanned in browser   lookscanned.io... · Posted by u/seedgou
Coryodaniel · 4 years ago
This is awesome. I’ve been using a gist[1] for years when dinosorgs need a wet signature

1. https://gist.github.com/andyrbell/25c8632e15d17c83a54602f6ac...

seedgou · 4 years ago
The site's logic is nearly identical to this gist: use ImageMagick to do the rotate, noise, etc.
seedgou commented on Show HN: Make your PDF look scanned in browser   lookscanned.io... · Posted by u/seedgou
Bedon292 · 4 years ago
Very nice. On thing I would like to see a rotation range for multi page PDFs. A 10 page document won't all be identical rotation. One might be -0.2 and the next 0.3.
seedgou · 4 years ago
Good idea! A random distribution on rotation seems a more user-friendly way instead of setting 10 rotation values.
seedgou commented on Show HN: Make your PDF look scanned in browser   lookscanned.io... · Posted by u/seedgou
moralestapia · 4 years ago
Great idea and props for shipping.

There's something extremely wrong with your implementation as it just takes too much to render every page.

I've done plenty of work in the past with both canvas and pdf.js (which is what you're using) and it shouldn't be that slow, at all. Perhaps you have a rogue loop that's calling a very expensive function on each pixel of every page, maybe?

Who knows, but for sure performance on that could be near real-time.

seedgou · 4 years ago
I didn't manipulate the data in pixel level. Maybe because I render PDF in 2x which causes 4x more pixels?
seedgou commented on Show HN: Make your PDF look scanned in browser   lookscanned.io... · Posted by u/seedgou
sp332 · 4 years ago
Cool idea, could you add some before/after samples?
seedgou · 4 years ago
There's an example PDF after clicking "START SCANNING" button. Maybe add more real-world examples.

u/seedgou

KarmaCake day378October 27, 2021
About
<github.com/rwv>
View Original