From 9083a1cce56a0735253824e7f40eaf4da174e2c8 Mon Sep 17 00:00:00 2001 From: Kuingsmile Date: Fri, 5 Jan 2024 18:43:59 -0800 Subject: [PATCH] :sparkles: Feature(custom): support specific format option for image conversion ISSUES CLOSED: #124 --- public/i18n/en.yml | 1 + public/i18n/zh-CN.yml | 1 + public/i18n/zh-TW.yml | 1 + src/renderer/pages/PicGoSetting.vue | 33 ++++++++++++++++++++++++++++- src/renderer/pages/Upload.vue | 32 +++++++++++++++++++++++++++- src/universal/types/i18n.d.ts | 1 + 6 files changed, 67 insertions(+), 2 deletions(-) diff --git a/public/i18n/en.yml b/public/i18n/en.yml index c4f9dcd..d91370a 100644 --- a/public/i18n/en.yml +++ b/public/i18n/en.yml @@ -120,6 +120,7 @@ UPLOAD_PAGE_IMAGE_PROCESS_ISREMOVEEXIF: Remove EXIF Info UPLOAD_PAGE_IMAGE_PROCESS_QUALITY: Compression Quality UPLOAD_PAGE_IMAGE_PROCESS_ISCONVERT: Convert Format UPLOAD_PAGE_IMAGE_PROCESS_CONVERTFORMAT: Destination Format +UPLOAD_PAGE_IMAGE_PROCESS_CONVERTFORMAT_SPECIFIC: 'Specific Format, Please enter in json format, e.g. {"png": "jpg"}' UPLOAD_PAGE_IMAGE_PROCESS_ISFLIP: Whether to flip vertically UPLOAD_PAGE_IMAGE_PROCESS_ISFLOP: Whether to flip horizontally UPLOAD_PAGE_IMAGE_PROCESS_ISRESIZE: Resize to fixed size diff --git a/public/i18n/zh-CN.yml b/public/i18n/zh-CN.yml index a39edc8..aeeeec7 100644 --- a/public/i18n/zh-CN.yml +++ b/public/i18n/zh-CN.yml @@ -120,6 +120,7 @@ UPLOAD_PAGE_IMAGE_PROCESS_ISREMOVEEXIF: 是否移除EXIF信息 UPLOAD_PAGE_IMAGE_PROCESS_QUALITY: 压缩质量 UPLOAD_PAGE_IMAGE_PROCESS_ISCONVERT: 是否转换格式 UPLOAD_PAGE_IMAGE_PROCESS_CONVERTFORMAT: 转换目的格式 +UPLOAD_PAGE_IMAGE_PROCESS_CONVERTFORMAT_SPECIFIC: '精细化转换格式, 请输入JSON格式,如: {"png": "jpg"}' UPLOAD_PAGE_IMAGE_PROCESS_ISFLIP: 是否进行垂直翻转 UPLOAD_PAGE_IMAGE_PROCESS_ISFLOP: 是否进行水平翻转 UPLOAD_PAGE_IMAGE_PROCESS_ISRESIZE: 是否按固定尺寸调整图片 diff --git a/public/i18n/zh-TW.yml b/public/i18n/zh-TW.yml index a5222d5..b298834 100644 --- a/public/i18n/zh-TW.yml +++ b/public/i18n/zh-TW.yml @@ -120,6 +120,7 @@ UPLOAD_PAGE_IMAGE_PROCESS_ISREMOVEEXIF: 是否移除EXIF信息 UPLOAD_PAGE_IMAGE_PROCESS_QUALITY: 壓縮質量 UPLOAD_PAGE_IMAGE_PROCESS_ISCONVERT: 是否轉換格式 UPLOAD_PAGE_IMAGE_PROCESS_CONVERTFORMAT: 轉換目的格式 +UPLOAD_PAGE_IMAGE_PROCESS_CONVERTFORMAT_SPECIFIC: '指定格式, 请输入JSON格式配置,如{"jpg":"png"}' UPLOAD_PAGE_IMAGE_PROCESS_ISFLIP: 是否進行垂直翻轉 UPLOAD_PAGE_IMAGE_PROCESS_ISFLOP: 是否進行水平翻轉 UPLOAD_PAGE_IMAGE_PROCESS_ISRESIZE: 是否按固定尺寸調整圖片 diff --git a/src/renderer/pages/PicGoSetting.vue b/src/renderer/pages/PicGoSetting.vue index a834e68..7cc3afb 100644 --- a/src/renderer/pages/PicGoSetting.vue +++ b/src/renderer/pages/PicGoSetting.vue @@ -1472,6 +1472,17 @@ /> + + + @@ -1664,6 +1675,8 @@ const waterMarkPositionMap = new Map([ ['centre', $T('UPLOAD_PAGE_IMAGE_PROCESS_POSITION_CENTER')] ]) +const imageExtList = ['jpg', 'jpeg', 'png', 'webp', 'bmp', 'tiff', 'tif', 'svg', 'ico', 'avif', 'heif', 'heic'] + const availableFormat = ['avif', 'dz', 'fits', 'gif', 'heif', 'input', 'jpeg', 'jpg', 'jp2', 'jxl', 'magick', 'openslide', 'pdf', 'png', 'ppm', 'raw', 'svg', 'tiff', 'tif', 'v', 'webp'] const waterMarkForm = reactive({ @@ -1686,13 +1699,15 @@ const compressForm = reactive({ isReSize: false, reSizeWidth: 500, reSizeHeight: 500, + skipReSizeOfSmallImg: false, isReSizeByPercent: false, reSizePercent: 50, isRotate: false, rotateDegree: 0, isRemoveExif: false, isFlip: false, - isFlop: false + isFlop: false, + formatConvertObj: '{}' }) function closeDialog () { @@ -1700,6 +1715,17 @@ function closeDialog () { } function handleSaveConfig () { + let formatConvertObj = {} + try { + formatConvertObj = JSON.parse(compressForm.formatConvertObj) + } catch (error) { + } + const formatConvertObjEntries = Object.entries(formatConvertObj) + const formatConvertObjEntriesFilter = formatConvertObjEntries.filter((item: any) => { + return imageExtList.includes(item[0]) && availableFormat.includes(item[1]) + }) + const formatConvertObjFilter = Object.fromEntries(formatConvertObjEntriesFilter) + compressForm.formatConvertObj = formatConvertObjFilter saveConfig('buildIn.compress', toRaw(compressForm)) saveConfig('buildIn.watermark', toRaw(waterMarkForm)) closeDialog() @@ -1723,6 +1749,11 @@ async function initForm () { compressForm.isRemoveExif = compress.isRemoveExif ?? false compressForm.isFlip = compress.isFlip ?? false compressForm.isFlop = compress.isFlop ?? false + try { + compressForm.formatConvertObj = JSON.stringify(compress.formatConvertObj ?? {}) + } catch (error) { + compressForm.formatConvertObj = '{}' + } } if (watermark) { waterMarkForm.isAddWatermark = watermark.isAddWatermark ?? false diff --git a/src/renderer/pages/Upload.vue b/src/renderer/pages/Upload.vue index e559e1c..d05d3b3 100644 --- a/src/renderer/pages/Upload.vue +++ b/src/renderer/pages/Upload.vue @@ -303,6 +303,17 @@ /> + + + @@ -474,6 +485,8 @@ const waterMarkPositionMap = new Map([ ['centre', $T('UPLOAD_PAGE_IMAGE_PROCESS_POSITION_CENTER')] ]) +const imageExtList = ['jpg', 'jpeg', 'png', 'webp', 'bmp', 'tiff', 'tif', 'svg', 'ico', 'avif', 'heif', 'heic'] + const availableFormat = ['avif', 'dz', 'fits', 'gif', 'heif', 'input', 'jpeg', 'jpg', 'jp2', 'jxl', 'magick', 'openslide', 'pdf', 'png', 'ppm', 'raw', 'svg', 'tiff', 'tif', 'v', 'webp'] const waterMarkForm = reactive({ @@ -503,7 +516,8 @@ const compressForm = reactive({ rotateDegree: 0, isRemoveExif: false, isFlip: false, - isFlop: false + isFlop: false, + formatConvertObj: '{}' }) function closeDialog () { @@ -511,6 +525,17 @@ function closeDialog () { } function handleSaveConfig () { + let formatConvertObj = {} + try { + formatConvertObj = JSON.parse(compressForm.formatConvertObj) + } catch (error) { + } + const formatConvertObjEntries = Object.entries(formatConvertObj) + const formatConvertObjEntriesFilter = formatConvertObjEntries.filter((item: any) => { + return imageExtList.includes(item[0]) && availableFormat.includes(item[1]) + }) + const formatConvertObjFilter = Object.fromEntries(formatConvertObjEntriesFilter) + compressForm.formatConvertObj = formatConvertObjFilter saveConfig('buildIn.compress', toRaw(compressForm)) saveConfig('buildIn.watermark', toRaw(waterMarkForm)) closeDialog() @@ -534,6 +559,11 @@ async function initData () { compressForm.isRemoveExif = compress.isRemoveExif ?? false compressForm.isFlip = compress.isFlip ?? false compressForm.isFlop = compress.isFlop ?? false + try { + compressForm.formatConvertObj = JSON.stringify(compress.formatConvertObj ?? {}) + } catch (error) { + compressForm.formatConvertObj = '{}' + } } if (watermark) { waterMarkForm.isAddWatermark = watermark.isAddWatermark ?? false diff --git a/src/universal/types/i18n.d.ts b/src/universal/types/i18n.d.ts index f7b9367..f3c494d 100644 --- a/src/universal/types/i18n.d.ts +++ b/src/universal/types/i18n.d.ts @@ -117,6 +117,7 @@ interface ILocales { UPLOAD_PAGE_IMAGE_PROCESS_QUALITY: string UPLOAD_PAGE_IMAGE_PROCESS_ISCONVERT: string UPLOAD_PAGE_IMAGE_PROCESS_CONVERTFORMAT: string + UPLOAD_PAGE_IMAGE_PROCESS_CONVERTFORMAT_SPECIFIC: string UPLOAD_PAGE_IMAGE_PROCESS_ISFLIP: string UPLOAD_PAGE_IMAGE_PROCESS_ISFLOP: string UPLOAD_PAGE_IMAGE_PROCESS_ISRESIZE: string