The invention discloses a multi-level quality compression method for picture which limits the file size threshold value at the browser end, including selecting the original picture file at the browser client end, determining whether the pixel size of the original picture file is larger than the pixel value set by the system, and, if so, compressing the pixels of the original picture file at multiple levels. The original image file after pixel multi-level compression is converted into binary data to determine whether the size of the binary data is larger than the data value set by the system. If so, the graded compression rate is generated according to the color difference of the original image file and the data value set by the system and the graded compression rate is applied to the binary data. The size of the data is multi-level compression processing; binary data after multi-level compression processing is encoded to form a new target picture file, and the target picture file is uploaded to the server. The invention preprocesses the picture before uploading the picture on the browser client side, effectively reducing the pressure on the server side.
【技术实现步骤摘要】
一种在浏览器端限定文件大小阀值的图片多级保质压缩方法
本专利技术涉及计算机领域,特别是一种在浏览器端限定文件大小阀值的图片多级保质压缩方法。
技术介绍
图片上传是现代web开发的一项广泛应用到的基础功能。随着照相机像素的提高,图片文件体积偏大,不同的业务场景对图片文件大小尺寸要求差异很大,针对不同业务场景上传不同体积大小的图片文件是强需求,目前现有的大多数图片文件压缩方案都是将用户原始图片直接上传到服务器后二次处理,缺点是原始图片文件较大,一般普通网络上行速度都比较慢,因此对大体积的图片文件上传过程偏慢,也消耗更多的带宽流量,进行服务端的二次处理转码压缩则占用了服务器资源,在高并发访问的时候对服务器资源消耗尤为明显,另一方面,市面少部分在浏览器端的图片预处理方法都基于普通的质量百分比模式对图片进行压缩,不能够直接有效将图片文件体积大小限定在有效阈值内。
技术实现思路
为解决上述技术问题,本专利技术的目的是提供一种在浏览器端限定文件大小阀值的图片多级保质压缩方法。本专利技术采用的技术方案是:一种在浏览器端限定文件大小阀值的图片多级保质压缩方法,包括:在浏览器客户端选择原 ...
【技术保护点】
1.一种在浏览器端限定文件大小阀值的图片多级保质压缩方法,其特征在于,包括:在浏览器客户端选择原始图片文件,判断原始图片文件的像素大小是否大于系统设定的像素值,若原始图片文件的像素大小大于系统设定的像素值,则对原始图片文件的像素进行多级压缩处理;将经过像素多级压缩处理后的原始图片文件转换成二进制数据,判断该二进制数据的大小是否大于系统设定的数据值,若二进制数据的大小大于系统设定的数据值,则根据该原始图片文件的色差以及系统设定的数据值生成分级压缩率并根据分级压缩率对该二进制数据的大小进行多级压缩处理;将经过大小多级压缩处理后的二进制数据编码形成新的目标图片文件,并将该目标图片文件上传至服务器。
【技术特征摘要】
1.一种在浏览器端限定文件大小阀值的图片多级保质压缩方法,其特征在于,包括:在浏览器客户端选择原始图片文件,判断原始图片文件的像素大小是否大于系统设定的像素值,若原始图片文件的像素大小大于系统设定的像素值,则对原始图片文件的像素进行多级压缩处理;将经过像素多级压缩处理后的原始图片文件转换成二进制数据,判断该二进制数据的大小是否大于系统设定的数据值,若二进制数据的大小大于系统设定的数据值,则根据该原始图片文件的色差以及系统设定的数据值生成分级压缩率并根据分级压缩率对该二进制数据的大小进行多级压缩处理;...
【专利技术属性】
技术研发人员:杨高岭,麦兴杰,陈倩,林汉升,
申请(专利权)人:广东微校信息科技有限公司,
类型:发明
国别省市:广东,44
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。