Possible to resize an image (client side) on an html form before upload?

后端 未结 1 526
甜味超标
甜味超标 2020-12-30 14:29

I have a standard html input form that includes a field for uploading a file (image).

I unfortunatly cannot edit the backend php that processes the file, but I need

1条回答
  •  Happy的楠姐
    2020-12-30 14:58

    You can use the new FileReader to let the user select an image from their local file system.

    Then you can use canvas to resize the image as needed.

    enter image description here

    This code lets the user select a local image file.

    The image will be scaled to half size on the client side.

    
    
    
    
    Image preview example
    
    
    
    
      

    Modern browsers support the FileReader (but for IE you need 10+).

    0 讨论(0)
提交回复
热议问题