问题

Am using canvas to resize image at the client side and then upload that image to the server. My intention was to resize the image to half of its original dimensions and wanted to see a decrease in the file size. But the resized image size is always greater than the original.

For example,

I was resizing a 2.5 MB JPEG image file with dimensions 2592 x 1936 to 1296 x 968 (JPEG file) and tried to upload it to the server. On the server I see that the file is saved with the 3.5 MB size.

Is there something that we can do while resizing with html5 canvas so that if we are decreasing the dimensions we could expect some decrease in the file size like compression.

回答1:

If you are using toDataURL, you can set the second argument to a number between 0.0 and 1.0. This is the JPEG quality level, with 1.0 meaning very high quality and a very large image and nearer to 0.0 meaning lower quality smaller image.

So, for example, you could try:

data = downsizedCanvas.toDataURL("image/jpeg", 0.2);

Here's a description in the w3c reference: www.w3.org: toDataURL

It looks like there has been a bug in Firefox to do with ignoring the quality, so you might need to test in some modern browsers.

来源:https://stackoverflow.com/questions/7168375/html5-canvas-resize

html resize 最小,Html5 Canvas resize相关推荐

  1. 基于php的地铁查询系统,HTML5 Canvas实现交互式地铁线路图

    这篇文章给大家介绍的文章内容是关于基于 HTML5 Canvas 的交互式地铁线路图,有很好的参考价值,希望可以帮助到有需要的朋友. 前言 前两天在 echarts 上寻找灵感的时候,看到了很多有关地 ...

  2. 520表白html,html5 canvas全屏的520爱心表白网页代码

    特效描述:html5 canvas全屏 520爱心表白 网页代码.html5 canvas制作520表白日,全屏的爱心和表白语网页动画代码,浪漫的520爱心表白动画特效. 代码结构 1. HTML代码 ...

  3. 如何使用HTML5 Canvas元素来裁剪图像

    本文介绍如何使用JavaScript和HTML5 Canvas元素来移动.调整大小和裁剪图像,这些技术适用于图片编辑器.照片分享等应用场景.借助HTML5 Canvas绘图功能,可以在浏览器端以比较简 ...

  4. html 流动效果,html5 canvas流动的海浪特效

    特效描述:html5canvas 流动的海浪特效.html5 canvas流动的海浪特效 代码结构 1. 引入JS 2. HTML代码 'use strict'; var gui = new dat. ...

  5. html 画动画效果,html5 canvas绘制曲线动画特效

    特效描述:html5 canvas绘制 曲线动画特效. 代码结构 1. HTML代码 Balls Size Speed Delay Go! Presets: Atomic Flower Spiro Y ...

  6. html5 canvas 图片移动端,支持移动端的HTML5 Canvas逼真黑板特效

    插件描述:这是一款使用HTML5 Canvas制作的黑板特效,该黑板特效支持手机移动端,它能模拟使用粉笔在黑板上写字的效果. 这是一款使用HTML5 Canvas制作的黑板特效,该黑板特效支持手机移动 ...

  7. html5 运动轨迹绘画,html5 canvas行星运动轨迹动画特效

    特效描述:html5 canvas 行星运动 轨迹动画特效.html5运动轨迹,行星动画特效 代码结构 1. 引入JS 2. HTML代码 Your browser doesn't support c ...

  8. php项目网页音乐播放器插件,基于HTML5 canvas和Web Audio的音频播放器插件

    wavesurfer.js是一款基于HTML5 canvas和Web Audio的音频播放器插件.通过wavesurfer.js你可以使用它来制作各种HTML5音频播放器,它可以在各种支持 Web A ...

  9. android 漩涡动画,html5 canvas酷炫的粒子漩涡动画特效

    特效描述:html5 canvas 粒子漩涡 动画特效.html5粒子漩涡动画,酷炫的粒子动画特效 代码结构 1. HTML代码 function project3D(x,y,z,vars){ var ...

最新文章

  1. Python,OpenCV基于支持向量机SVM的手写数字OCR
  2. HTML发送语音,上传音频PHP接收
  3. IDNO简单生成方法
  4. 简单module_深入理解JavaScript之全面解析Module模式
  5. DPDK vhost-user之mergeable 特性(七)
  6. 实现本机拷贝带进度的方法
  7. npm升级package.json依赖包
  8. BNU OJ 第26303 题 Touchscreen Keyboard
  9. 利用D触发器和异或门实现两个IO解读电机编码器的计数值和方向
  10. androidstudio build tools安装_Android Studio4.0 安装及配置
  11. selenium + java po模式
  12. mysql查询图书复本量_SQL语句在图书管理数据库中实现下列查询S1:在借阅表中查询哪些 爱问知识人...
  13. 4块硬盘掉线导致服务器崩溃解决过程
  14. 废旧闲置的笔记本除了电脑回收,这两招也很实用!
  15. 计算机没有有效的ip配置,win7电脑没有有效的ip配置怎么办
  16. 路由器、AC、AP及POE交换机理解
  17. Android内存泄漏分析
  18. 用计算机弹咱们结婚吧乐谱,用计算器弹奏“周杰伦”,这些乐谱也太简单了吧!...
  19. java html pdf 中文_java html 转pdf 中文可显示
  20. Mojarra JSF ViewState 反序列化漏洞复现

热门文章

  1. ajax 上传文件实例,Ajax异步上传文件实例代码分享
  2. 西交大计算机考博学术英语,2018年西安交通大学考博英语真题
  3. android string.format()长度,Android通过String.format格式化(动态改变)字符串资源的显示内容...
  4. 【Golang 接口自动化05】使用yml管理自动化用例
  5. 20165101刘天野 2017-2018-2 《Java程序设计》 结对编程练习_四则运算(第二周)
  6. Jexus vs IIS8 非绝对客观对比测试
  7. Model-Based RL前沿追踪——以无法为有法,以无形为有形
  8. Scikit-learn 更新至0.24版,这10个新特性你需要了解
  9. 如何突破科研瓶颈?如何与导师自在相处?微软研究员们的读博心得
  10. AI Hero 算法挑战赛,万元奖金等你来拿!