效果圖
創(chuàng)新互聯(lián)是一家專業(yè)提供香河企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站建設(shè)、網(wǎng)站制作、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為香河眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。html結(jié)構(gòu)
body{
background-color: #000;
}
#canvas{
display: block;
margin: 0 auto;
border: 1px solid #aaa;
}
.range-style{
display: block;
margin: 20px auto;
width: 800px;
}
.watermark-canvas-style{
display: block;
margin: 0 auto;
border: 1px solid #aaa;
}
js腳本
var canvas = document.getElementById("canvas");
var slider = document.getElementById("scale-range");
var watermarkCanvas = document.getElementById("watermark-canvas");
var context = canvas.getContext("2d");
var watermarkContext = watermarkCanvas.getContext("2d");
var image = new Image();
window.onload = function(){
canvas.width = 600;
canvas.height = 450;
var scale = slider.value;
console.log(scale);
image.src = "20170122161717.png";
image.onload = function(){
// context.drawImage(image,0,0,canvas.width,canvas.height);
drawImageByScale(scale);
slider. = function(){
scale = slider.value;
drawImageByScale(scale);
}
}
watermarkCanvas.width = 500;
watermarkCanvas.height = 100;
watermarkContext.font = "bold 50px Arial";
watermarkContext.fillStyle = "rgba(255,255,255,0.5)";
watermarkContext.textBaseline = "middle";
watermarkContext.fillText("%:)%yunshuo%:)%",20,50);
}
function drawImageByScale(scale){
var imageWidth = 600 * scale;
var imageHeight = 450 * scale;
// var sx = imageWidth / 2 - canvas.width / 2;
// var sy = imageHeight / 2 - canvas.height / 2;
// context.drawImage(image,sx,sy,canvas.width,canvas.height,0,0,canvas.width,canvas.height);
var dx = canvas.width / 2 - imageWidth / 2;
var dy = canvas.height / 2 - imageHeight / 2;
context.clearRect(0,0,canvas.width,canvas.height);
context.drawImage(image,dx,dy,imageWidth,imageHeight);
context.drawImage(watermarkCanvas,canvas.width - watermarkCanvas.width,canvas.height - watermarkCanvas.height);
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。