title: How can I crop an image in p5.js without drawing image on the screen
body: <p>I've researched and found that you can "crop" an image by using <a href="https://stackoverflow.com/questions/46574273/p5-js-is-there-a-way-to-cut-out-an-image-area">get()</a>, but the image has to be drawn on the screen where you then take a section of the canvas. Is it possible to load an image then save a cropped version of it in a variable? So maybe something like this:</p>
  
  <pre><code>var img;
  var cropped;
  
  function preload(){
    img = imageLoad('dog.png', crop)
  }
  
  function crop(image){
    cropped = crop(img, 0, 0, img.w/2, img.h) // Getting left half of image 
  }
  </code></pre>
  
  <p>Thank you.</p>
  
  <hr>
  
  <p>EDIT:
  This is the function I made using copy(), but I don't know if there's an easier way that I'm missing.</p>
  
  <pre><code>function crop(image, x, y, w, h) {
    var cropped = createImage(w, h);
    cropped.copy(image, x, y, x + w, y + h, 0, 0, x + w, y + h)
    return cropped;
  }
  </code></pre>