I have a large image tif format and two small images.
What I wanted to achieve is that I want to embed either of the two small images on top of a large image and save it using JavaScript.
<html>
<body>
<img src="largeimg" />
<p>Select the image to embed on the large image</p>
<img src="smallimg1" />
<img src="smallimg2" />
</body>
</html>
Is there any way to achieve the above using javascript?
If the images are on the same origin the it is possible to use canvas.
canvascanvas.toDataURL()to retrieve the image dataimgelement and append data to itExample:
HTML:
JavaScript:
If you want to write the image on
[0, 0]coordinates then you don’t have to usedata-attributes, of course. Problem with this approach is that if the files are hosted on different origin thentoDataURLwill throw security error.Based on: https://stackoverflow.com/a/934925/1011582
Note: I would like to link jsfiddle or jsbin example but because of the same origin policy I cannot create any reasonably looking example. Any ideas?
THIS is the best example I was able to get (tested with Chrome & FF).