Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are several separate things here:</p> <ul> <li><p>Validating image/file type. This can be done at the client side, but you will need to do it at the server again for security. For a file input that only accepts images, you can use:</p> <pre><code>&lt;input type="file" accept='image/*'&gt; </code></pre></li> <li><p>Letting the user crop the image. There are several libraries here, the most prominent one being Jcrop. But there are alternatives, like imgareaselect, jqCrop and jquery-cropbox (I created and mantain the jquery-cropbox). See here for a very minimal example on how you can get started with one or two lines of jquery.</p></li> </ul> <p><a href="http://acornejo.github.io/jquery-cropbox/" rel="nofollow">http://acornejo.github.io/jquery-cropbox/</a></p> <ul> <li>Doing the actual cropping at the client. This requires HTML5, and therefore won't work with older version of internet explorer. In particular you will need the canvas api, and possibly the file api (to serve the files). jquery-cropbox can also do this for you through the <code>getBlob</code> and <code>getDataURL</code> methods. If you want to do it by hand, take a look here:</li> </ul> <p><a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D</a></p> <ul> <li><p>Uploading the image. There are plenty of scripts for uploading images out there, take your pick. If you are using jquery-cropbox, then you can use jquery to handle the upload to your server like this (uploading client generated form data like this will also require an HTML5 compliant browser).</p> <pre><code>var blob = $('#yourimage').data('cropbox').getBlob(); var fd = new FormData(); fd.append('file', blob); $.ajax({ type: 'POST', url: 'http://yourwebsite.com/handle_uploads', data: fd, cache: false, contentType: false, processData: false, success: function(data){ alert('upload succeeded'); }, error: function () { alert('upload failed'); } }); </code></pre> <p>},</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload