当前位置: 首页 > news >正文

网站建设运维策划承德网站制作公司哪家好

网站建设运维策划,承德网站制作公司哪家好,杭州seo网站推广软件,WordPress单页添加JsEdge 浏览器插件开发#xff1a;图片切割插件 在图片处理领域#xff0c;按比例切割图片是一个常见需求。本文将带你开发一个 Edge 浏览器插件#xff0c;用于将用户上传的图片分割成 4 个部分并自动下载到本地。同时#xff0c;本文介绍如何使用 cursor 辅助工具来更高效…Edge 浏览器插件开发图片切割插件 在图片处理领域按比例切割图片是一个常见需求。本文将带你开发一个 Edge 浏览器插件用于将用户上传的图片分割成 4 个部分并自动下载到本地。同时本文介绍如何使用 cursor 辅助工具来更高效地实现和调试插件功能。 先看效果 点击分割图片后 功能概述 插件的主要功能包括 用户上传并预览图片。将图片平均分割成 4 份。自动下载分割的图片到本地默认文件夹。 通过 cursor 辅助工具我们可以高效地管理代码中的事件和操作流确保插件在多个步骤中流畅运行并能够在图片加载、分割和下载的每个关键步骤中实时监控进程状态。 使用 cursor 辅助工具 在插件开发中cursor 工具可以帮助我们实现多步事件的顺序执行和状态管理。下面的代码将展示如何在 popup.js 中利用 cursor 来管理图片处理流程。 开发步骤 1. 创建项目结构 在项目目录下创建以下文件 manifest.json插件的配置文件。popup.html插件的用户界面。popup.js实现插件的核心逻辑和 cursor 功能。icons 目录存储插件的图标文件如 icon16.png、icon48.png 等。 2. 配置 manifest.json manifest.json 是插件的核心配置文件声明了插件的基础信息和权限。该插件需要 downloads 权限来下载图片到本地。代码如下 {manifest_version: 3,name: 图片分割工具,version: 1.0,description: 将图片平均分割成4份并下载,action: {default_popup: popup.html,default_icon: {16: icons/icon16.png,32: icons/icon32.png,48: icons/icon48.png,128: icons/icon128.png}},permissions: [downloads] }3. 设计用户界面 popup.html 在 popup.html 中设计用户界面包括文件选择器、图片预览、分割按钮和状态显示区域 !DOCTYPE html html headmeta charsetUTF-8stylebody { width: 300px; padding: 10px; font-family: Arial, sans-serif; }#preview { max-width: 100%; margin: 10px 0; border: 1px solid #ccc; }.button { width: 100%; padding: 8px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; }.button:disabled { background-color: #cccccc; }#status { margin-top: 10px; color: #333; background-color: #f0f0f0; border-radius: 4px; padding: 5px; }/style /head bodyinput typefile idimageInput acceptimage/*img idpreview styledisplay: none;button idsplitButton classbutton disabled分割图片/buttondiv idstatus请选择一张图片/divscript srcpopup.js/script /body /html4. 实现核心逻辑 popup.js popup.js 中使用 cursor 工具来管理图片处理步骤包括加载、分割、和自动下载。 // 使用 cursor 工具在多步流程中跟踪状态和事件 import cursor from cursor;document.addEventListener(DOMContentLoaded, function() {const imageInput document.getElementById(imageInput);const preview document.getElementById(preview);const splitButton document.getElementById(splitButton);const status document.getElementById(status);let originalImage null;let originalFileName ;const showStatus cursor.create({defaultStatus: 请选择一张图片,updateStatus: function(message) {status.textContent message;console.log(message);}});imageInput.addEventListener(change, function(e) {const file e.target.files[0];if (file) {originalFileName file.name.replace(/\.[^/.]$/, );showStatus.updateStatus(正在加载图片...);const reader new FileReader();reader.onload function(event) {preview.src event.target.result;preview.style.display block;originalImage new Image();originalImage.src event.target.result;originalImage.onload function() {splitButton.disabled false;showStatus.updateStatus(图片已加载尺寸: ${originalImage.width}x${originalImage.height});};};reader.readAsDataURL(file);}});splitButton.addEventListener(click, async function() {try {if (!originalImage) {showStatus.updateStatus(请先选择图片);return;}splitButton.disabled true;showStatus.updateStatus(开始分割图片...);const canvas document.createElement(canvas);const ctx canvas.getContext(2d);const partWidth Math.floor(originalImage.width / 2);const partHeight Math.floor(originalImage.height / 2);canvas.width partWidth;canvas.height partHeight;for (let row 0; row 2; row) {for (let col 0; col 2; col) {ctx.clearRect(0, 0, canvas.width, canvas.height);ctx.drawImage(originalImage,col * partWidth, row * partHeight,partWidth, partHeight,0, 0,partWidth, partHeight);const blob await new Promise(resolve canvas.toBlob(resolve, image/png));const url URL.createObjectURL(blob);try {await chrome.downloads.download({url: url,filename: ${originalFileName}_split_${row1}x${col1}.png,saveAs: false});showStatus.updateStatus(已完成 ${row * 2 col 1}/4 张图片);} catch (error) {console.error(下载失败:, error);showStatus.updateStatus(下载失败: ${error.message});} finally {URL.revokeObjectURL(url);}}}showStatus.updateStatus(所有图片分割完成);} catch (error) {console.error(处理过程出错:, error);showStatus.updateStatus(处理出错: ${error.message});} finally {splitButton.disabled false;}}); });运行与测试 1. 加载插件 在 Edge 浏览器中访问 edge://extensions/启用“开发者模式”选择“加载已解压的扩展程序”并选择项目文件夹。 2. 测试流程 上传一张图片确认图片是否成功显示在预览区域。点击“分割图片”按钮观察插件是否顺利完成图片分割和下载。 3. cursor 调试优势 进度实时更新cursor 帮助我们实时跟踪每一步的状态如“图片加载中”、“开始分割图片”等让用户直观地了解操作进度。错误捕捉与提示利用 cursor 定位和反馈错误信息确保用户在出现异常时能够清楚知道原因。 总结与扩展思路 通过本插件我们了解了图片分割处理的基本流程以及如何借助 cursor 工具在插件开发中高效管理流程。插件在 Edge 和 Chrome 浏览器上均可运行并支持进一步扩展例如添加用户自定义切割比例、支持不同的文件格式和 UI 优化。 借助 cursor你可以让插件的事件流更可控、流程更顺畅。这为进一步优化插件功能和用户体验提供了良好的基础。如果你有其他想法或改进建议欢迎一起讨论 参考网址https://mp.weixin.qq.com/s/KZt5-3OxCtlwuTKhplzGCg 完整代码网址https://github.com/yyq2024/split_image
http://www.w-s-a.com/news/43498/

相关文章:

  • fifa17做任务网站app下载免费安装
  • 网站开发用哪些技术seo是什么意思为什么要做seo
  • 网站会动的页面怎么做的与网站建设有关的招标文件
  • 公司网站如何做seowordpress付费资源
  • 福田做商城网站建设哪家公司便宜点WordPress安装子目录
  • 南京建设交易中心网站wordpress 拼车
  • 上海今天发生的重大新闻5条河南网站seo费用
  • 广东深圳最新情况临安网站seo
  • 华为快速建站女人做春梦网站
  • 建外贸网站费用手机排行榜zol
  • 长治网站制作的网站做网站要什么知识条件
  • discuz 做门户网站wordpress怎么添加图片不显示图片
  • 东营网站建设方案范文百度应用搜索
  • 网站 常见推广js代码放wordpress哪里
  • 靖江网站开发徐州住房和城乡建设局网站
  • 南宁网站建设公司如何为老板打造网站赚钱的wordpress optimizer
  • 做微商好还是开网站好网站网络推广
  • 网站建设岗位所需技能泊头网站优化
  • 企业网站建设是什么网络营销岗位介绍
  • 网站做cdn怎么弄昆明网站seo报价
  • 拖拽网站如何建立微网站
  • 网站网站做代理微信群卖房卡南宁建站模板大全
  • 网络公司怎么优化网站百度快速排名技术培训教程
  • 建e室内设计网 周婷站长工具seo综合查询源码
  • 塔式服务器主机建网站定制美瞳网站建设
  • 网站是先解析后备案吗永久免费网站模板
  • wordpress站点演示php根据ip 跳转网站
  • 东莞市凤岗建设局网站网站开发有哪些职位
  • 企业网站手机版模板免费下载辣条网站建设书
  • 南昌网站建设维护vc 做网站源码