         if err
           return done err
         img = new Image
+        img.onerror = done
+        img.onload = () ->
+          canvas = new Canvas img.width, img.height
+          canvas.getContext('2d').drawImage(img, 0, 0)
+          ins.beginGroup 'foo'
+          ins.send canvas
         img.src = image
-        canvas = new Canvas img.width, img.height
-        canvas.getContext('2d').drawImage(img, 0, 0)
 
-        ins.beginGroup 'foo'
-        ins.send canvas
+

        if err
          return done err
        img = new Image
        img.src = image
        canvas = new Canvas img.width, img.height
        canvas.getContext('2d').drawImage(img, 0, 0)
        done()

    it 'should have correct image and canvas size', ->
      chai.expect(img.width).to.equal 1439

            if err
              return done err
            img = new Image
            img.onerror = done
            img.onload = () ->
              canvas = new Canvas img.width, img.height
              canvas.getContext('2d').drawImage(img, 0, 0)
              done()
            img.src = image

      it 'should have correct image and canvas size', ->
        chai.expect(img.width).to.equal 1
