簡體   English   中英

如何使用javaScript在圖片文件(png)中添加文本?

[英]How to add Text IN a picture file (png) with javaScript?

我發現我不能用HTML做到這一點(在圖片中添加文字),我找到了一種使用JAVA的方法,但我很有興趣通過使用Javascript找到一種方法。

你可以用帆布做,

<canvas id="canvas" width="340" height="340"></canvas>

腳本,

function addTextToImage(imagePath, text) {
    var circle_canvas = document.getElementById("canvas");
    var context = circle_canvas.getContext("2d");

    // Draw Image function
    var img = new Image();
    img.src = imagePath;
    img.onload = function () {
        context.drawImage(img, 0, 0);
        context.lineWidth = 1;
        context.fillStyle = "#CC00FF";
        context.lineStyle = "#ffff00";
        context.font = "18px sans-serif";
        context.fillText(text, 50, 50);
    };
}
addTextToImage("http://www.gravatar.com/avatar/0c7c99dec43bb0062494520e57f0b9ae?s=256&d=identicon&r=PG", "Your text");

http://jsfiddle.net/wAY6Y/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM