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

网站开发网站设计的标准免费大数据网站

网站开发网站设计的标准,免费大数据网站,js网站模板,昌邑市建设局官方网站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.yidumall.com/news/55342.html

相关文章:

  • 美工做图素材网站2021最火关键词
  • 河池市住房和城乡建设厅网站百度官方官网
  • 北京网络科技公司简介搜狗seo培训
  • 手机做图片的网站腾讯企点官网下载
  • 苏州企业网站制作宁波关键词网站排名
  • 什么专业是做网站网络广告营销
  • 怎么做班级网站seo关键词排名优化系统源码
  • 网站怎么推广出去比较好网页入口网站推广
  • 微网站搭建教程最佳磁力吧ciliba搜索引擎
  • 渭南公司做网站网络公司网络推广服务
  • 深圳服装网站建设交换链接营销实现方式解读
  • 网站和数字界面设计师2023上海又出现疫情了
  • 织梦网站主页底小程序开发公司
  • 沙河网站建设深圳关键词推广整站优化
  • wordpress 富文本编辑器北京网站优化外包
  • wordpress整站加密网优工程师前景和待遇
  • 网络和网站的区别电商网站开发
  • 政府的网站应该怎么做门户网站怎么做
  • 微网站建设哪家好东莞谷歌推广公司
  • ftp中如何找到网站首页精准客源引流平台
  • 百度站长推送厦门排名推广
  • 注册了一个域名怎么做网站搜索引擎关键词广告
  • 如何做网站效果更好网站营销策划
  • 网站建设及管理使用情况汇报百度关键词挖掘
  • 网站流量指标有哪些网络推广营销技巧
  • 上海第五届进博会河南网站seo
  • 广州疫情风险等级最新消息合肥百度seo排名
  • 如何查看网站是什么语言做的有网站模板怎么建站
  • 成都程序员网站站长之家备案查询
  • 网站案例网站建设网页设计成品源代码