怎么将js生成的图片自动保存到本地
form.submit(function(event){event.preventDefault();varimg_name=$(this).serializeArray...
form.submit(function(event){
event.preventDefault();
var img_name = $(this).serializeArray()[0].value,
img_src = img.find('img').attr('src');
if(img_name.length == 0){
$('#error_container').html('<p class="bg-danger" >Please, enter the pattern for names of images!</p>').fadeIn().delay(3000).fadeOut();
return false;
}
if(img_src == undefined || img_src == 'http://www.forkosh.com/mimetex.cgi?...'){
$('#error_container').html('<p class="bg-danger" >Image not found</p>').fadeIn().delay(3000).fadeOut();
return false;
}
var reg1 = /(?!_)\d+$/, // index from numbers (123)
reg2 = /\w+_/, // string pattern for images name (lection_)
// if this is first saved image then index = 1
index = reg1.exec(img_name) !== null ? reg1.exec(img_name)[0] : 1;
img_name = reg2.exec(img_name) !== null ? reg2.exec(img_name)[0] : img_name + '_';
var filename = img_name + '.png';
var canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d"),
image = new Image();
image.onload = function () {
canvas.width = image.width;
canvas.height = image.height;
ctx.drawImage(image, 0, 0);
canvas.toBlob(function(blob) {
saveAs(
blob
, (filename.value || filename.placeholder) + ".png"
);
}, "image/png");
};
index ++;
form.find('input').val(img_name + index);
image.src = img_src; 展开
event.preventDefault();
var img_name = $(this).serializeArray()[0].value,
img_src = img.find('img').attr('src');
if(img_name.length == 0){
$('#error_container').html('<p class="bg-danger" >Please, enter the pattern for names of images!</p>').fadeIn().delay(3000).fadeOut();
return false;
}
if(img_src == undefined || img_src == 'http://www.forkosh.com/mimetex.cgi?...'){
$('#error_container').html('<p class="bg-danger" >Image not found</p>').fadeIn().delay(3000).fadeOut();
return false;
}
var reg1 = /(?!_)\d+$/, // index from numbers (123)
reg2 = /\w+_/, // string pattern for images name (lection_)
// if this is first saved image then index = 1
index = reg1.exec(img_name) !== null ? reg1.exec(img_name)[0] : 1;
img_name = reg2.exec(img_name) !== null ? reg2.exec(img_name)[0] : img_name + '_';
var filename = img_name + '.png';
var canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d"),
image = new Image();
image.onload = function () {
canvas.width = image.width;
canvas.height = image.height;
ctx.drawImage(image, 0, 0);
canvas.toBlob(function(blob) {
saveAs(
blob
, (filename.value || filename.placeholder) + ".png"
);
}, "image/png");
};
index ++;
form.find('input').val(img_name + index);
image.src = img_src; 展开
1个回答
博思aippt
2024-07-20 广告
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询