Commit faa0790b by doszhang

dos

parent 3a22a2fd
...@@ -31,33 +31,35 @@ var picUrl = window.base_resource_url + '/images/'; ...@@ -31,33 +31,35 @@ var picUrl = window.base_resource_url + '/images/';
var preloadImageList = [ var preloadImageList = [
// picUrl + 'share.png', // picUrl + 'share.png',
]; ];
if ($('div').length > 0) { if ($('div').length > 0) {
$.each($('div'), function (index, val) { $.each($('div'), function (index, val) {
var img = $(val).css('background-image').replace(/^url\((['"]?)(.*)\1\)$/, '$2'); var img = $(val).css('background-image').replace(/^url\((['"]?)(.*)\1\)$/, '$2');
img = $.trim(img); img = $.trim(img);
if (img && img.match(/[^/]+(jpg|png|gif)$/)) { if (img && img.match(/[^/]+(jpg|png|gif)$/)) {
preloadImageList.push(img); preloadImageList.push(img);
} }
}); });
} }
var myCanvas; var uploadCanvas;
var ctx; var headimgCanvas;
var uploadctx;
var headimgctx;
var imgInfo = {}; var imgInfo = {};
var nowTemplate = 1; var nowTemplate = 1;
// var username = '';
preloadimages(preloadImageList, function () { preloadimages(preloadImageList, function () {
}, function (progress) { }, function (progress) {
}); });
$('input[name=customize]').attr('placeholder','输入自定义文字(仅限四个字)').attr('maxlength','4'); $('input[name=customize]').attr('placeholder','输入自定义文字(仅限四个字)').attr('maxlength','4');
$('.canvas-block').html('<canvas id="myCanvas" width="'+ 330 +'" height="'+ 330 +'"></canvas>'); $('.canvas-block').html('<canvas id="uploadCanvas" width="'+ 330 +'" height="'+ 330 +'"></canvas>');
$('.headimg-canvas-block').html('<canvas id="headimgCanvas" width="'+ 330 +'" height="'+ 330 +'"></canvas><img id="headimg" />');
$('.page1').show(); $('.page1').show();
...@@ -75,8 +77,12 @@ $(document).ready(function () { ...@@ -75,8 +77,12 @@ $(document).ready(function () {
$('.btn-slideleft').on('click',slidePrevTemplate); $('.btn-slideleft').on('click',slidePrevTemplate);
$('.btn-slideright').on('click',slideNextTemplate); $('.btn-slideright').on('click',slideNextTemplate);
$('.btn-toheadimg').on('click',createHeadimg);
$('[name=btn-tocreate]').change(function() { $('[name=btn-tocreate]').change(function() {
initCanvas(); var canvasinfo = initCanvas('#uploadCanvas',660,660);
uploadCanvas = canvasinfo[0];
uploadctx = canvasinfo[1];
imgInfo.rotation = 0; imgInfo.rotation = 0;
imgInfo.x = 0; imgInfo.x = 0;
imgInfo.y = 0; imgInfo.y = 0;
...@@ -88,16 +94,16 @@ $(document).ready(function () { ...@@ -88,16 +94,16 @@ $(document).ready(function () {
var orientation = EXIF.getTag(this, "Orientation"); var orientation = EXIF.getTag(this, "Orientation");
switch (orientation) { switch (orientation) {
case 3: case 3:
imgInfo.rotation = 180; imgInfo.rotation = 180;
break; break;
case 6: case 6:
imgInfo.rotation = 90; imgInfo.rotation = 90;
break; break;
case 8: case 8:
imgInfo.rotation = 270; imgInfo.rotation = 270;
break; break;
default: default:
imgInfo.rotation = 0; imgInfo.rotation = 0;
} }
if (navigator.userAgent.indexOf('iPhone') > -1) { if (navigator.userAgent.indexOf('iPhone') > -1) {
imgInfo.rotation = 0; imgInfo.rotation = 0;
...@@ -179,6 +185,26 @@ $(document).ready(function () { ...@@ -179,6 +185,26 @@ $(document).ready(function () {
}); });
}); });
function createHeadimg() {
var headimgObj = new Image();
headimgObj.src = getManBase64(uploadCanvas);
var canvasinfo = initCanvas('#headimgCanvas',660,660);
headimgCanvas = canvasinfo[0];
headimgctx = canvasinfo[1];
headimgObj.onload = function() {
headimgctx.drawImage(headimgObj,0,0);
var frameimg = new Image();
frameimg.src = '/Public/static/image2/frame' + nowTemplate + '.png';
frameimg.onload = function() {
headimgctx.drawImage('frameimg',0,0);
}
}
}
function homeBtnGoHandleClick() function homeBtnGoHandleClick()
{ {
$('.subtitle,.copywriting1,.btn-go').fadeOut(300); $('.subtitle,.copywriting1,.btn-go').fadeOut(300);
...@@ -210,14 +236,14 @@ function slideNextTemplate() { ...@@ -210,14 +236,14 @@ function slideNextTemplate() {
} }
function drawImage() { function drawImage() {
ctx.save(); uploadctx.save();
ctx.clearRect(0, 0, myCanvas.width, myCanvas.height); uploadctx.clearRect(0, 0, uploadCanvas.width, uploadCanvas.height);
ctx.translate(myCanvas.width / 2, myCanvas.height / 2); uploadctx.translate(uploadCanvas.width / 2, uploadCanvas.height / 2);
ctx.translate(imgInfo.x, imgInfo.y); uploadctx.translate(imgInfo.x, imgInfo.y);
ctx.rotate(Math.PI / 180 * imgInfo.rotation); uploadctx.rotate(Math.PI / 180 * imgInfo.rotation);
ctx.scale(imgInfo.scale, imgInfo.scale); uploadctx.scale(imgInfo.scale, imgInfo.scale);
ctx.drawImage(img, -img.width / 2, -img.height / 2); uploadctx.drawImage(img, -img.width / 2, -img.height / 2);
ctx.restore(); uploadctx.restore();
} }
function checkWord(name,callback) { function checkWord(name,callback) {
...@@ -240,8 +266,8 @@ function checkWord(name,callback) { ...@@ -240,8 +266,8 @@ function checkWord(name,callback) {
}) })
} }
function getManBase64() { function getManBase64(canvas) {
return myCanvas.toDataURL('image/png'); return canvas.toDataURL('image/png');
} }
function initGame() { function initGame() {
...@@ -276,12 +302,13 @@ function txtDraw(ctx, content, x, y, fontsize, fontweight, color) { ...@@ -276,12 +302,13 @@ function txtDraw(ctx, content, x, y, fontsize, fontweight, color) {
// } // }
} }
function initCanvas() { function initCanvas(id,canvasWidth,canvasHeight) {
myCanvas = $('#myCanvas')[0]; canvas = $(id)[0];
ctx = myCanvas.getContext("2d"); ctx = canvas.getContext("2d");
ctx.scale(2,2); ctx.scale(2,2);
myCanvas.width = 660; canvas.width = canvasWidth;
myCanvas.height = 660; canvas.height = canvasHeight;
return [canvas, ctx];
} }
function getTranslateDistance(cardinal = 0) { function getTranslateDistance(cardinal = 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment