Home > front end >  Jquery tilt how to set up a text watermark images?
Jquery tilt how to set up a text watermark images?

Time:12-02

On the Internet to find a picture to add text watermarking case, now I want to add text watermark to the middle of the picture or the lower right, hope great god answer, want to write out the code, write where I need to pay attention to what! Thank you




//HTML img

//JS page
<script SRC="https://bbs.csdn.net/js/jquery-1.12.4.min.js" type="text/javascript" & gt; </script>
<script SRC="https://bbs.csdn.net/js/img2blob.js" type="text/javascript" & gt; </script>
$(function () {
//the default
$(" sample1 "). Img2blob ();

//with watermark
$(". "the sample2). Img2blob ({
Watermark: 'watermark watermark watermark,
FontStyle: 'Microsoft YaHei, Arial,
FontSize: '45',//p
FontColor: 'yellow',//the default 'black'
The font: 40,//The x coordinate The where to start painting The text
FontY: 60,//The y coordinate The where to start painting The text
});

});
</script>

//img2blob. Js

$. Fn. Img2blob=function (a) {
Var b={
Watermark: "'
FontStyle: 'Arial,
FontSize: '30',
FontColor: 'black',
FontX: 10,
FontY: 50,
};
If (typeof a==='object') {
Aleem walji atermark=(aleem walji atermark==undefined? B.w atermark: aleem walji atermark);
A.f ontStyle=(a.f ontStyle==undefined? B. ontStyle: a.f ontStyle);
A.f ontSize=(a.f ontSize==undefined? B. ontSize: a.f ontSize);
A.f ontColor=(a.f ontColor==undefined? B. ontColor: a.f ontColor);
A.f ontX=(a.f ontX==undefined? B. ontX: a.f ontX);
A.f ontY=(a.f ontY==undefined? B. ontY: a.f ontY);
} else {
a=b;
}

$(this). Each (function (I, c) {
Var d=$(this). The data (' img2blob),
E='+ $(this). Attr (' class'),
F=new Image ();
F.o nload=function () {
Var g=document. The createElement method (' canvas');
G.w idth=motor aturalWidth;
We eight=motor aturalHeight;
Var h=g.g etContext (" 2 d ");
H.d rawImage (f, 0, 0);
If (aleem walji atermark!=' ') {
H.f ont=a.f ontSize + 'px + a.f ontStyle;
H.f illStyle=a.f ontColor;
H.f illText (aleem walji atermark, a.f ontX, a.f ontY);
}
Var j=g.t oDataURL (' image/PNG '),
K=DataUriToBinary (j),
L=new Blob ([k], {
Type: 'image/PNG'
}),
M=window. URL. CreateObjectURL (l);
$(e). Eq (I). Attr (' SRC ', m);
};
F.s rc=https://bbs.csdn.net/topics/d;
});

The function DataUriToBinary (n) {
Var o='; Base64, ', '
P=n.i ndexOf (o) + o.l ength,
Q=n.s ubstring (p),
R=window. Atob (q),
S=r.l ength,
T=new Uint8Array (new ArrayBuffer (s));
for (i=0; i [I] t=r.c harCodeAt (I);
}
return t;
}

}
Code from https://hovertree.com/h/bjag/kfq30wnj.htm
  • Related