188 points · by akmittal · 4y ago · 103 comments
Webutils convert all images on client using webassembly.
Here are a few ideas to make yours faster:
1. Use the browser's canvas element to compress JPEG or PNG images instead of WASM. The libraries which come with browsers can use processor-specific instructions, while WASM only targets the smallest common denominator of the most common architectures, so it will be slower.
2. Which resizing method are you using to find a fitting image size? For me, it worked well enough to downscale by some factor a few times until it fits, but if you want to get super close, you could use binary search.
https://caniuse.com/mdn-api_paintrenderingcontext2d_imagesmo...
I'm completely new to WASM but excited to learn — how did you use the Squoosh repo to turn it into WASM, and how did you embed that into your app? Is that just a static file you can "import" and use in the client?
And can anything be "turned into" WASM (e.g. a python library), or is that kind of a new paradigm of writing code from scratch?
> Any pure Python package with a wheel available on PyPi is supported. Many packages with C extensions have also been ported for use with Pyodide. These include many general-purpose packages such as regex, PyYAML, lxml and scientific Python packages including NumPy, pandas, SciPy, Matplotlib, and scikit-learn.
For now wasm can be compiled from C,C++, Rust and Go, so mostly compiled languages. https://emscripten.org/ can help compile C,C++, Rust and Go has native support to compile. There is also a Typescript like language which compile to wasm(assembly script)
Python or most dynamic languages are too difficult to compile to wasm.
WASM is a compilation target for AOT compiled code.
On a similar note, does anyone know similar lightweight web/desktop apps for basic photo editing, specifically, resize, conversion, crop, color overlay, etc. I use Photopea[0] on Linux but I still feel I could go lighter.
[0]: https://photopea.com
did you compile some c++ library into wasm or js is enough to do the job?
It’s 100% private, editing happens in the browser.
I found that it starts to hang on XLSX files ~50MB because the spreadsheet model it produces get's a bit too big and sheetjs dies. Doing this in a web worker is a good idea because otherwise it will clog the main thread.
For CSV the story is different, because you can read a plain text file in chunks (even in JS) with FileReader and readAsArrayBuffer(file.slice(byteOffset, byteOffset + chunkSize, file.type)).
Sadly, because of the nature of the web, one can never be sure that the image actually stays within the browser. There's no way to prevent it from secretly sending everything you convert with this to some shady website because it runs in the browser. I trust the people behind this just fine, but sadly the promise of offline-level privacy and running code inside the browser just don't go well together.
The thing is, that logic applies just as well to desktop apps. There's never any guarantee on either desktop or web unless you have very specific counter-measures in place (firewalls, airgapping, ...).
It's just "closer to the web" when it runs in the browser, but if malice is the intent, it's as likely on either. Desktop apps are just "harder" to install.
A website might serve a different code every time you use it. It might even serve a malicious code specifically for some users.
Desktop apps can do this little trick, too. Also, many desktop apps can enlist the help of other desktop apps using the three decades or so of various ways our OSes have made to lett apps talk to each other. Bad actors were using macro languages in desktop apps long before the invention of the web browser. Now, it's just as easy for a desktop app to hit an endpoint, grab a script (shell or macro language) and then execute it. The browser is just another desktop app - one with much more scrutiny than that MP3 tagging thing with a built in Lua interpreter that Bob in sales just gave local admin privileges to...
Oh, and most desktop apps have some level of access to your identity - or outright have you confirm your identity when you activate your license.
Windows Firewall commonly serves this purpose even among users who are not familiar with terms like “countermeasures.” The only problem with their system is, the warnings are so common that clicking through them becomes a reflex action.
While not impossible, the likelihood of, say, imagemagick doing this, while going through this process, is extremely improbable.
I agree that just downloading apps off random websites is every bit as risky as a browser app.
But who does that?!
(The last statement was sarcastic, and aimed at the curl | bash crowd, the nodejs crowd, the composer crowd... these things are the polar opposite of trusted, secured, audited, safe, sensible.)
what about:
* DNS leaks (eg. trying to connect to payloadhere454098357987.attacker.example, leaks payloadhere454098357987 to the attacker)
* websocket
* webRTC
* prefetching
* service workers (background sync)
* beacons
* CSP reports
Disconnect wifi of on Desktop, but agree with OP there is no good way to check if processing is actually happening locally.
I wish browsers, Android, and iOS had this option so that users could be confident that the app/site doesn't have access to the internet. Maybe a little tricky with a browser but perhaps it could be possible somehow.
If you do not trust the developer of a web app, you can always disconnect from your Wi-Fi, use the app, close the tab and then reconnect to your Wi-Fi.
Web browsers don't come with such a firewall, and they need to be permitted by the system firewall to operate normally. It's technically possible to block outgoing requests with addons and configuration, but that's a pain to get right, especially compared to the simple toggle you can find in most OS firewalls.
Resize to particular size idea came, when online service asked me to upload image upto 25KB. I had to just keep on changing size till image became 25KB.
But most people are not comfortable using CLI or someone may just not want to install it for one off conversion. Also webapp works on smartphones, tablets or anything with browser, while Imagemagick does not.
Imagemagick is ofcourse lot more feature rich and fast. If anyone is already comfortable using Imagemagick, webapp is not for them.
I don't see the value of commendeering a browser to run applications that would run more efficiently on the OS natively.
In future planning to make the app available offline using service worker. So first time internet would be required, next time onwards without internet also it will work.
If the data never leaves the local, how is it online?
"Bulk convert images in the browser without sending to server" seems more appropriate
Thats not true, because everything is client side, you just open app once. Next time onwards resources are cached and served from browser cache.