Merge Image using Javascript

后端 未结 6 1513
青春惊慌失措
青春惊慌失措 2020-12-01 01:39

Is it possible to merge pictures using javascript?

For example, if you have 2 rectangle .jpg or .png images files of the same size, is it possible that you can align

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 02:09

    Huỳnh Quốc Phong is partially right:

    You can use Canvas to merge images. But they can origin from other domains. Just load the pictures in your dom . Once the pictures are loaded (can be checked with javascript, see below) you can use them in your canvas.

    var canvas = canvasBuild.getContext('canvasObj');
    var img = document.getElementById('mergePic1');
    canvas.drawImage(img, 0, 0);
    

    To check if the images were loaded, I would recommend using the jQuery plugin http://desandro.github.io/imagesloaded/ - but it can also be done without.

提交回复
热议问题