如何减小文件大小意味着在使用Query上传到服务器之前调整图像大小?

时间:2016-06-30 11:07:14

标签: javascript jquery html

<input type="file" id="selectedPhoto" name="profilepicuploader1" 
       onclick="PreviewImage();" accept="image/*" /> 
<img id="profileImage" >

这是我的剧本:

function PreviewImage() {
  document.getElementById('selectedPhoto').onchange = function(evt) {
    ImageTools.resize(
      this.files[0], 
      {
        width: 150, // maximum width
        height:150 // maximum height
      }, 
      function(blob, didItResize) {
        // didItResize will be true if it managed to resize it, otherwise                
        //false (and will return the original file as 'blob')
        document.getElementById('profileImage').src=window.URL.createObjectURL(blob);
      })
  };
}

上面的代码调整了图像的大小,并使用document.getElementById('profileImage').src = window.URL.createObjectURL(blob);显示预览图像 但我想将预览图像值分配到输入file类型 请事先帮助我

0 个答案:

没有答案