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

网站 托管种子搜索引擎 磁力天堂

网站 托管,种子搜索引擎 磁力天堂,高效网站建设与维护岗位职责,电子工程网账号OPEN-IMAGE-TINY,一个基于 Electron VUE3 的图片压缩工具,项目开源地址:https://github.com/0604hx/open-image-tiny ℹ️ 需求描述 在上一篇文章一段代码利用 snapdom 将 CSDN 博文转化为长图片(PNG/JPG/PDF)中&…

OPEN-IMAGE-TINY,一个基于 Electron + VUE3 的图片压缩工具,项目开源地址:https://github.com/0604hx/open-image-tiny

ℹ️ 需求描述

在上一篇文章一段代码利用 snapdom 将 CSDN 博文转化为长图片(PNG/JPG/PDF)中,我截取到一张长图,想要垂直切割成多张高度一致的小图。虽然用美图秀秀之类的软件很快就能做到,奈何我觉得图片压缩工具也应该有这样的一个功能,于是就有了这篇文章😄。

功能说明:

  • 只需要按设定的高度垂直切割
  • 最后一张小图高度不足时填充指定颜色

🧑‍💻 核心代码

后端

//electron\tool.js
/*** @typedef {Object} SplitConfig - 切割配置* @property {Number} height - 高度* @property {Boolean} fit - 是否自动填充* @property {String} bgColor - 填充颜色** 垂直切割图片** @param {String} origin - 原图片* @param {SplitConfig} config - 配置*/
exports.splitImageVertical = async (origin, config)=>{const { width, height } = await this.readImgSize(origin)config.fit ??= trueconst ext = path.extname(origin)const count = Math.ceil(height / config.height)const outputDir = path.join(path.dirname(origin), `${path.basename(origin, ext)}-${config.height}px`)if(!existsSync(outputDir))mkdirSync(outputDir)const image = sharp(origin)let fileCount = 0let started = Date.now()for(let i=0;i<count;i++){const top = i * config.heightconst curHeight = Math.min(config.height, height - top)let chunk = image.clone().extract({ left:0, top, width, height: curHeight })//自动填充白色背景if(config.fit === true && config.height > curHeight){chunk = chunk.extend({ top:0, bottom: config.height - curHeight, left:0, right:0, background: config.bgColor||"#ffffff" })}let outFile = path.join(outputDir, `切割-${i+1}.${ext}`)await chunk.toFile(outFile)console.debug(`切割图片 > ${outFile}`)fileCount ++}return { total:fileCount, dir: outputDir, used: Date.now() - started }
}

注册 ipcMain 处理函数:

const handlers = {/**** @param {Electron.IpcMainInvokeEvent} e* @param {String} filePath* @param {import("./tool").SplitConfig} config* @returns {Object}*/'split': async (e, filePath, config)=> await splitImageVertical(filePath, config)
}

UI界面

<template><n-form :show-feedback="false" label-placement="left"><n-flex vertical><n-form-item label="切割高度"><n-input-number class="cell" :min="0" :step="50" v-model:value="config.height"><template #suffix><Tag>px</Tag></template></n-input-number></n-form-item><n-form-item label="自动填充"><n-switch v-model:value="config.fit" /></n-form-item><n-form-item v-if="config.fit==true" label="填充颜色"><n-color-picker v-model:value="config.bgColor" :show-alpha="false" /></n-form-item><n-button block type="primary" secondary :loading @click="toSplit">开始切割</n-button></n-flex></n-form>
</template><script setup>const props = defineProps({img:{ type:Object }})const config = reactive({ height:1000, fit:true, bgColor:"#ffffff" })const loading = ref(false)const toSplit=()=>{if(config.height >= props.img.height) return M.warn(`切割高度不能大于图片原高度`)loading.value = trueH.action('split', props.img.path, toRaw(config)).then(v=>{loading.value = falselet { total, dir, used } = vM.dialog({maskClosable: false, showIcon: true,title: `切割完成`,content: `共生成 ${total} 张小图,耗时 ${used} 毫秒。`,positiveText:"打开图片文件夹",onPositiveClick: ()=>H.action('open', dir)})})}
</script>

🚀 界面实现

http://www.dtcms.com/wzjs/486789.html

相关文章:

  • 南宁网站建设公司seo优化百度官网下载
  • 龙岗附近网站开发公司电商代运营
  • 网站建设教程 企业邮箱青岛百度关键词优化
  • java视频教学网站开发seo优缺点
  • 做公司门户网站的重点网络推广文案有哪些
  • 药品推广策略有哪些襄阳seo培训
  • 网页制作与网站建设试题百度搜索排名优化
  • 负责网站建设推广网络推广公司运营
  • 如何做优秀的视频网站设计关键一招
  • 洮南市城乡和住房建设局网站友情链接教程
  • 网站开发视频教学搜索引擎大全排行
  • wordpress 无刷新评论南京百度搜索优化
  • 佛山网站建设专家百度网盘app
  • 德州做网站网站的营销推广
  • 网站设计功能seo技术优化整站
  • 网站设计入门百度搜索榜
  • 河北城乡建设厅网站杭州seo软件
  • 做网站用什么格式的图片百度竞价是什么意思?
  • 天元建设集团有限公司标志黑帽seo技术
  • 淘宝客做网站链接网站创建的流程是什么
  • 网站二维码悬浮做神马seo快速排名软件
  • 房山网站建设优化seo网络广告文案
  • wordpress的设置网址导航seo机构
  • 甜品网站开发需求分析中国seo
  • 淄博网站制作企业高端天津关键词优化网排名
  • 深圳低价网站建设seo日常工作都做什么的
  • 菠萝之乡网站建设seo网站优化培
  • html做校园网站免费下载b站视频软件
  • 网站制作用什么软件sem和seo的关系
  • 设计的好网站网站推广优化招聘