压缩base64数据的uri图像 [英] Compressing base64 data uri images
问题描述
我创建了多个图表,然后发送到服务器以创建PDF。这些数据可能会变大。
问题
压缩并将图像数据发送到服务器
背景 图表I创建相当复杂,为了节省自己的头痛,所有这些都转换成了一个生成base64数据uri的画布。目前,数据uri(s)被发布到服务器来处理处理。发布的信息可以在相当大的范围内获得大约400-600kb的小图表和12mb的最大图表。 图表是可以操纵/重新排序的组织结构图。 b 是否有更好的方法在将这些字符串发送回服务器之前将其压缩? 研究 我检查了一些内容: https://github.com/brunobar79/JIC/blob/master/ src / JIC.js (看起来不像一个选项只是调整大小) http://pastebin.com/MhJZBsqW (看起来很有趣) 但引用外部库,我找不到: https://code.google.com/ p / jslzjb / source / browse / trunk / Iuppiter.js?r = 2 (看起来像这样可以工作,但依赖于服务器端的解压缩) 也许字符串压缩是您的解决方案。这将数据转换为字节数组。 有许多实现和算法,例如 LZMA-JS Lempel-Ziv-Markov链的独立JavaScript实现(LZMA)压缩算法。 lz-string : JavaScript压缩,快! Problem I'm creating multiple charts that are then sent to the server to create a PDF. This data can get large. Question What is the best way to compress and send the image data to the server Background The charts I'm creating are fairly complex, to save myself the headache all of this is converted to a canvas where the base64 data uri is generated. Currently the data uri(s) are posted to the server to handle the processing. Posted info can get fairly large at around 400-600kb each for a small chart and 12mb for the largest chart. The charts are org charts that can be manipulated/reordered. Is there a better method of compressing these strings before sending it back up to the server? Research Some things I've check out: https://github.com/brunobar79/J-I-C/blob/master/src/JIC.js (does not look like an option just resizes) http://pastebin.com/MhJZBsqW (looks interesting) But references external libraries that I cannot find: https://code.google.com/p/jslzjb/source/browse/trunk/Iuppiter.js?r=2 (looks like this could work but relies on decompression on server side) Maybe string compression is the solution for you. This converts the data to byte arrays. There are multiple implementations and algorithms around, for instance LZMA-JS A standalone JavaScript implementation of the Lempel-Ziv-Markov chain (LZMA) compression algorithm. lz-string: JavaScript compression, fast! 这篇关于压缩base64数据的uri图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b
C_H_Image
Lib_MinifyJpeg
my_lzma = new LZMA(./lzma_worker.js);
my_lzma.compress(This is my compression test。,1,function on_compress_complete(result){
console.log(Compressed:+ result);
my_lzma.decompress(result ,函数on_decompress_complete(result){
console.log(Decompressed:+ result);
},函数on_decompress_progress_update(percent){
console.log(Decompressing:+(percent * 100)+%);
});
},函数on_compress_progress_update(百分比){
console.log(Compressing:+(percent * 100)+% );
});
var str =这是我的压缩测试。;
console.log(样本的大小是:+ str.length);
var compressed = LZString.compress(str);
console.log(压缩样本的大小是:+ compressed.length);
str = LZString.decompress(compressed);
console.log(Sample is:+ str);
C_H_Image
Lib_MinifyJpeg
my_lzma = new LZMA("./lzma_worker.js");
my_lzma.compress("This is my compression test.", 1, function on_compress_complete(result) {
console.log("Compressed: " + result);
my_lzma.decompress(result, function on_decompress_complete(result) {
console.log("Decompressed: " + result);
}, function on_decompress_progress_update(percent) {
console.log("Decompressing: " + (percent * 100) + "%");
});
}, function on_compress_progress_update(percent) {
console.log("Compressing: " + (percent * 100) + "%");
});
var str = "This is my compression test.";
console.log("Size of sample is: " + str.length);
var compressed = LZString.compress(str);
console.log("Size of compressed sample is: " + compressed.length);
str = LZString.decompress(compressed);
console.log("Sample is: " + str);