4 ms·
Show HN: JavaScript image compressor
- dsun176 9y agoInput (original) name: Fuckscape_d80352_5915762.jpg type: image/jpeg size: 19.14 KB Output (compressed) name: Fuckscape_d80352_5915762.jpg type: image/jpeg size: 20.64 KB (-7.85% off) So your image-compressor actually adds 7.85% to the filesize? Maybe I don't understand the meaning of compression, but shouldn't it be smaller?
- andreasklinger 9y agoyou should share an image link plus your settings/script to make this useful for OP
- deleted 9y ago[deleted]
- dankent 9y agoI got better results: Input (original) name: the-northern-trifid-nebula-8499-1920x1200.jpg type: image/jpeg size: 737.26 KB Output (compressed) name: the-northern-trifid-nebula-8499-1920x1200.jpg type: image/jpeg size: 263.17 KB (64.30% off) I guess your original was more optimised than mine. A tool like this should definitely check to make sure it has actually reduced the file size and, if not, just return the original with a note that it couldn't make any gains.
- deleted 9y ago[deleted]
- phoboslab 9y agoThe result is dependent on your Browser. This library uses the Browser's native `ctx.toDataURL('image/jpeg', quality)` method to re-encode the image. The actual compression algorithm is not implemented in JavaScript.
- atonse 9y agoThis could be a great (although not really real-world) addition to a JS benchmark suite.
- MaxLeiter 9y agoI was really hoping this would implement some complex algorithm or at least be an interesting implementation, however, it seems to just divide the image height/width by the aspect ratio: https://github.com/xkeshi/image-compressor/blob/master/src/index.js#L80-L87 https://github.com/xkeshi/image-compressor/blob/master/src/i...
- phoboslab 9y agoAs I understand it, this library draws the image into a Canvas to then re-compress the Canvas' via the Browser's native `toDataURL('image/jpeg', quality);`. You can optionally specify a width/height to downscale the image. Imho the readme needs to state what the library actually does. E.g. "This takes a user image from a file input, optionally resizes it, and returns a JPEG, PNG or WebP as a Blob, ready to upload."
- octalmage 9y agoAgreed! I haven't looked into this at all but I wonder if you can run some algorithm on the datauri.
- ratsz 9y agoThis is a simple resize using canvas.drawImage(). Since data is permanently lost in the output file, it is misleading to call it compression.