plog-基础布局

This commit is contained in:
tangly1024.com
2023-07-11 13:39:53 +08:00
parent 463b35639a
commit 563b130e77
8 changed files with 133 additions and 21 deletions

View File

@@ -6,7 +6,7 @@ import BLOG from '@/blog.config'
* 2. UnPlash 图片可以通过api q=50 控制压缩质量 width=400 控制图片尺寸
* @param {*} image
*/
const compressImage = (image, width = 300) => {
const compressImage = (image, width = 400, quality = 50, fmt = 'webp') => {
if (!image) {
return null
}
@@ -20,11 +20,12 @@ const compressImage = (image, width = 300) => {
// 获取URL参数
const params = new URLSearchParams(urlObj.search)
// 将q参数的值替换
params.set('q', '50')
params.set('q', quality)
// 尺寸
params.set('width', width)
// 格式
params.set('fmt', 'webp')
params.set('fmt', fmt)
params.set('fm', fmt)
// 生成新的URL
urlObj.search = params.toString()
return urlObj.toString()