Javascript无损图像压缩
我正在寻找一种在浏览器中将 bmp 图像编码为 tiff 或其他标准、压缩但无损格式的方法(javascript)。我想如果最坏的情况发生,我可以自己编写一个库(从画布元素获取数据),但我希望:有更好的方法来做到这一点,或者其他人已经写了类似的东西(我找不到图书馆)。
我有用户想要上传 ~ 4mb(8 位单色)bmp 文件,我可以使用 LZW 将其无损压缩为 ~700kb tiff 文件(甚至更好 ~300kb 无损 JPEG-2000)。我想在上传文件之前执行此操作,以节省传输成本/时间。
在你问之前,我并不是在谈论无损编码,而只是使用高比特率 JPEG。这些是用于分析的天文照片,因此它们无法处理引入的任何压缩伪影。
谢谢, 强尼
I am looking for a way to encoding a bmp image as a tiff or some other standard, compressed but lossless format in a browser (javascript). I guess if worst comes to worst I can write a library myself (getting the data from a canvas element) but I was hoping either: there's a better way to do it or someone else has already written something similar (I can't find a library).
I have users wanting to upload ~ 4mb (8-bit monochrome) bmp files, which I can losslessly compress to ~700kb tiff files with LZW (or even better ~300kb lossless JPEG-2000). I'd like to do this before the files are uploaded to save transfer costs/time.
Before you ask, I'm not being anal about the lossless encoding instead of just using high bitrate JPEG. These are astronomy photos that are used for analysis so they can't handle any compression artifacts being introduced.
Thanks,
Jonny
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用PNG。它是无损的并使用 zlib 压缩。甚至有像 pngcrush 这样的程序可以优化图像的大小(唯一的问题是需要一段时间为了这)。
您在这个过程中使用 JavaScript 有什么原因吗?从长远来看,如果您在 Java 小程序中执行此操作(使用与
java.awt.Image
类),或将其上传到进行图像处理并返回压缩后的服务器图像?编辑:请不要使用Java小程序;该技术不再得到良好的支持。
Use PNG. It's lossless and uses zlib compression. There are even programs like pngcrush that will optimize the image for size (only problem is it takes a while for this).
Is there any reason you're using JavaScript of all things for this process? Wouldn't it be easier in the long run if you did it in a Java applet (using a library that interfaces with the
java.awt.Image
class), or uploaded it to a server that did the image processing and returned the compressed image?Edit: Please don't use a Java applet; the technology isn't well-supported anymore.
如果你愿意尝试新的东西,你可以尝试我创建的新的无损压缩算法;通过 Java 小程序,可以在浏览器中可视化压缩图像。您可以使用Javascript来触发applet的加载,或者直接操作Java代码(该程序是开源的)。对于许多图像来说,压缩率会比无损 Jpeg 2000 更好。网站地址是 http://www .researchandtechnology.net/bcif/。
如果您想使用一些众所周知的标准,那么我同意 amphetamachine:使用 PNG 将是最好的选择。
这么久,
斯特凡诺
If you are willing to experiment something new, you could try a new lossless compression algorithm I created; through a Java applet it is possible to visualize the compressed images in a browser. You could use Javascript to trigger the loading of the applet, or manipulate directly the Java code (the program is open source). For many images, the compression ratio will be better than lossless Jpeg 2000. The address of the website is http://www.researchandtechnology.net/bcif/ .
If instead you want to use some well-known standard, then I'd agree with amphetamachine: using PNG would be the best choice.
So long,
Stefano