[英]How to auto-compress Images while uploading image in angularjs
Here is my HTML form: 这是我的HTML表单:
<form name="myForm" ng-submit=""> <input ng-model='file' type="file"/> <input type="submit" value='Submit'/> </form>
I want to upload an image. 我要上传图片。 Here if the file size is big(like 3 or 4 MB), I want to compress image automatically to 1MB or less than that. 在这里,如果文件很大(例如3或4 MB),我想将图像自动压缩到1MB或更小。 Any options are there to autocompress images in angularjs or javascript. 可以使用任何选项来自动压缩angularjs或javascript中的图像。
you can use image-compressor, where you can specify your desired height and width of your image. 您可以使用图像压缩器,在其中可以指定所需的图像高度和宽度。
https://www.npmjs.com/package/image-compressor https://www.npmjs.com/package/image-compressor
This Angular directive compresses jpeg or png files using angularjs on client side. 此 Angular指令在客户端使用angularjs压缩jpeg或png文件。 Read more about it here 在这里了解更多
This module depends on angularjs
, so make sure you've added angularjs
dependency and then angular-image-compress.js
. 该模块取决于angularjs
,因此请确保已添加angularjs
依赖项,然后添加了angular-image-compress.js
。 Something like 就像是
angular.module('myApp', ['ngImageCompress']);
This is how you can achieve what you want. 这是您可以实现所需目标的方法。
<input id="inputImage" type="file" accept="image/*" image="image1" resize-max-height="800" resize-max-width="800" resize-quality="0.7" resize-type="image/jpg" ng-image-compress />
Directives
used in above input
tag are self explanatory 上面的input
标记中使用的Directives
不言自明
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.