Jump to content
Sign in to follow this  

Canvas API image optimisation from file Input

Recommended Posts

unable to understand why black image is getting, please check the code and assist in generating the optimised image from file input :)

  <script src="jquery-3.4.1.min.js"></script>
  <title>Image Optimization</title>
      <input type="file" id="imgFile" accept="image/*" capture="user">
  <div id ="test">
      <img id="optImg" alt="optmisied Image">
   const File = this.files[0];
   const fileURL = URL.createObjectURL(File);
   const cvs = document.createElement("canvas");
   let ctx = cvs.getContext("2d");
   const imgFile = new Image();
   imgFile.src = fileURL;
   imgFile.onload = function(){
   const cvsURL = cvs.toDataURL(File.type, 0.3);

please assist

Edited by khan.sikki

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...