From https://github.com/betamax/getImageData/blob/master/server-examples/getImageData.php