You can use binary Ajax in modern browsers to fetch a resource as a file:
var oReq = new XMLHttpRequest();
oReq.open("GET", fileURLGivenByUser, true);
oReq.responseType = "blob";
oReq.onload = function(oEvent) {
var oFile = oReq.response;
processTheFileSomehow(oFile);
};
oReq.send();
This will work as long as either:
fileURLGivenByUser
is on the same domain as the page running the script (e.g., your cropping script runs onfoo.com
and the image link is also onfoo.com
), orA target image resource is served with the
Access-Control-Allow-Origin: *
CORS response header (e.g., your cropping script runs onfoo.com
, the image link is onbar.com
, andbar.com
serves the file with acceptable CORS headers)
So, for your user to use a localhost
link, the user must be running a local Web server, and that Web server must serve its images with Access-Control-Allow-Origin: *
or Access-Control-Allow-Origin: whateverdomainyouuse.com
(i.e., whatever domain your cropping script runs on).
If the CORS restrictions are too restrictive (they likely are), you can use a server-side proxy on your host. For example, when you request
http://mydomain.com/proxy/http://targetdomain.com/image.png
the server does a request and responses with the contents of
http://targetdomain.com/image.png