S
S
Sergey Savostin2014-12-18 16:16:57
JavaScript
Sergey Savostin, 2014-12-18 16:16:57

Is it possible to get img from a third-party server, draw something and give it to the client for saving?

There is a certain page, on it img with src to a third-party site.
You need to make a change to the picture (add an inscription) and do "Save file as".
Without the participation of my server, i.e. purely on the client.
You cannot add Access-Control-Allow-Origin: * to the image title.
For "save as" I use FileSaver.js , but "on the forehead" it gives the error "Tainted canvases may not be exported". Maybe there is some workaround? Can somehow get img in a different way, say through "new Image ()"? Yes, at least copy it pixel by pixel ...
The code is like this:

var canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
ctx.fillText("Hello World!",10,50);
canvas.toBlob(function(blob) {
saveAs(blob, 'saved.png');
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question