uni-canvas-image 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/common/index.js +4 -5
- package/src/util/attractImage.js +10 -10
- package/src/util/coverImage.js +1 -1
- package/src/util/houseImage.js +2 -2
- package/src/util/noteImage.js +2 -2
package/package.json
CHANGED
package/src/common/index.js
CHANGED
|
@@ -2,7 +2,6 @@ export const directionEnum = { NORTH: '北', EAST: '东', SOUTH: '南', WEST: '
|
|
|
2
2
|
|
|
3
3
|
export async function getImageInfo(src, targetRatio) {
|
|
4
4
|
return new Promise(async (resolve, reject) => {
|
|
5
|
-
if (src && src.endsWith('.mp4')) src = src.replace('.mp4', '.png')
|
|
6
5
|
if (src) {
|
|
7
6
|
const imageInfo = await uni.getImageInfo({ src })
|
|
8
7
|
const newImageInfo = {
|
|
@@ -49,7 +48,7 @@ export async function base64ToBlob(base64Data) {
|
|
|
49
48
|
|
|
50
49
|
export async function drawImageToCanvas(arr, canvasId = 'canvas-1', api, config) {
|
|
51
50
|
return new Promise((resolve, reject) => {
|
|
52
|
-
const { bgc = '#fff' } = config || {}
|
|
51
|
+
const { bgc = '#fff', className = '' } = config || {}
|
|
53
52
|
const ctx = uni.createCanvasContext(canvasId)
|
|
54
53
|
ctx.setFillStyle(bgc)
|
|
55
54
|
ctx.fillRect(0, 0, 375, 300)
|
|
@@ -91,15 +90,15 @@ export async function drawImageToCanvas(arr, canvasId = 'canvas-1', api, config)
|
|
|
91
90
|
ctx.clearRect(0, 0, 375, 300)
|
|
92
91
|
let filePath
|
|
93
92
|
// #ifdef MP-WEIXIN
|
|
94
|
-
filePath = tempRes
|
|
93
|
+
filePath = tempRes
|
|
95
94
|
// #endif
|
|
96
95
|
// #ifdef H5
|
|
97
96
|
const blob = await base64ToBlob(tempRes.tempFilePath)
|
|
98
|
-
filePath = URL.createObjectURL(blob)
|
|
97
|
+
filePath.tempFilePath = URL.createObjectURL(blob)
|
|
99
98
|
// #endif
|
|
100
99
|
if (!api) return resolve(filePath)
|
|
101
100
|
else {
|
|
102
|
-
const { result } = await api(
|
|
101
|
+
const { result } = await api({ filePath, className })
|
|
103
102
|
resolve(result)
|
|
104
103
|
// #ifdef MP-WEIXIN
|
|
105
104
|
uni.getFileSystemManager().unlink({ filePath })
|
package/src/util/attractImage.js
CHANGED
|
@@ -10,15 +10,15 @@ async function attractImage(params) {
|
|
|
10
10
|
const { data, canvasId, api } = params
|
|
11
11
|
const staticInfo = [
|
|
12
12
|
{ type: 'rect', x: 16, y: 34, width: 320, height: 16, color: '#00ffb7' },
|
|
13
|
-
{ type: 'text', text: '主要区域:', x: 16, y: 29, color: '#000', fontSize:
|
|
14
|
-
{ type: 'text', text: data.buildingCount, x:
|
|
15
|
-
{ type: 'text', text: '楼盘数量', x: 280, y:
|
|
16
|
-
{ type: 'text', text: data.houseCount, x:
|
|
17
|
-
{ type: 'text', text: '房源数量', x: 280, y:
|
|
13
|
+
{ type: 'text', text: '主要区域:', x: 16, y: 29, color: '#000', fontSize: 18 },
|
|
14
|
+
{ type: 'text', text: data.buildingCount, x: 346 - String(data.buildingCount).length * 24, y: 80, color: '#FF703B', fontSize: 46, fontWeight: 700 },
|
|
15
|
+
{ type: 'text', text: '楼盘数量', x: 280, y: 132, color: '#000', fontSize: 20 },
|
|
16
|
+
{ type: 'text', text: data.houseCount, x: 346 - String(data.houseCount).length * 24, y: 196, color: '#FF703B', fontSize: 46, fontWeight: 700 },
|
|
17
|
+
{ type: 'text', text: '房源数量', x: 280, y: 248, color: '#000', fontSize: 20 },
|
|
18
18
|
]
|
|
19
19
|
// 区域信息
|
|
20
20
|
const areaInfo = data.mainArea.length > 3 ? data.mainArea.slice(0, 3).join('、') + '...' : data.mainArea.join('、')
|
|
21
|
-
const newAreaInfo = { type: 'text', text: areaInfo, x:
|
|
21
|
+
const newAreaInfo = { type: 'text', text: areaInfo, x: 100, y: 24, color: '#000', fontSize: 24, fontWeight: 600 }
|
|
22
22
|
// 图片信息
|
|
23
23
|
const imgInfo = await getImageInfo(data.buildingUrl, 230 / 210)
|
|
24
24
|
const newImgInfo = {
|
|
@@ -29,11 +29,11 @@ async function attractImage(params) {
|
|
|
29
29
|
dHeight: 210,
|
|
30
30
|
}
|
|
31
31
|
const maskInfo = { type: 'rect3' }
|
|
32
|
-
const buildingLabel = { type: 'text', text: '主营楼盘:', x: 22, y: 260, color: '#fff', fontSize:
|
|
33
|
-
data.mainBuilding = data.mainBuilding.join('、').length >
|
|
34
|
-
const newBuildingInfo = { type: 'text', text: data.mainBuilding, x:
|
|
32
|
+
const buildingLabel = { type: 'text', text: '主营楼盘:', x: 22, y: 260, color: '#fff', fontSize: 14 }
|
|
33
|
+
data.mainBuilding = data.mainBuilding.join('、').length > 8 ? data.mainBuilding.join('、').slice(0, 8) + '...' : data.mainBuilding.join('、')
|
|
34
|
+
const newBuildingInfo = { type: 'text', text: data.mainBuilding, x: 86, y: 258, color: '#fff', fontSize: 16 }
|
|
35
35
|
const newObj = [...staticInfo, newAreaInfo, newImgInfo, maskInfo, buildingLabel, newBuildingInfo]
|
|
36
|
-
const url = await drawImageToCanvas(newObj, canvasId, api, { bgc: '#f2f2f2' })
|
|
36
|
+
const url = await drawImageToCanvas(newObj, canvasId, api, { bgc: '#f2f2f2', className: 'share-attract-card' })
|
|
37
37
|
resolve(url)
|
|
38
38
|
})
|
|
39
39
|
}
|
package/src/util/coverImage.js
CHANGED
|
@@ -27,7 +27,7 @@ const coverImage = (params = {}) => {
|
|
|
27
27
|
type: 'image',
|
|
28
28
|
}
|
|
29
29
|
})
|
|
30
|
-
const url = await drawImageToCanvas(newDrawImgs, canvasId, api)
|
|
30
|
+
const url = await drawImageToCanvas(newDrawImgs, canvasId, api, { className: 'share-cover-card' })
|
|
31
31
|
resolve(url)
|
|
32
32
|
})
|
|
33
33
|
}
|
package/src/util/houseImage.js
CHANGED
|
@@ -46,7 +46,7 @@ async function handleItem(obj, canvasId, api) {
|
|
|
46
46
|
const tagsInfos = hanleTagsInfo(obj.tags.slice(0, 3), 14, 212)
|
|
47
47
|
const categoryInfos = handleCategoryInfo(obj, categoryEnum)
|
|
48
48
|
const newObj = [newImgInfo, ...titleInfos, ...tagsInfos, ...categoryInfos]
|
|
49
|
-
const url = await drawImageToCanvas(newObj, canvasId, api)
|
|
49
|
+
const url = await drawImageToCanvas(newObj, canvasId, api, { className: 'share-house-card' })
|
|
50
50
|
resolve(url)
|
|
51
51
|
})
|
|
52
52
|
}
|
|
@@ -90,7 +90,7 @@ function handleItems(arr, canvasId, api) {
|
|
|
90
90
|
const categoryInfos = handleCategoryInfo(obj, category)
|
|
91
91
|
newObj.push(newImgInfo, ...titleInfos, ...tagsInfos, ...categoryInfos)
|
|
92
92
|
}
|
|
93
|
-
const url = await drawImageToCanvas(newObj, canvasId, api)
|
|
93
|
+
const url = await drawImageToCanvas(newObj, canvasId, api, { className: 'share-multi-house-card' })
|
|
94
94
|
resolve(url)
|
|
95
95
|
})
|
|
96
96
|
}
|
package/src/util/noteImage.js
CHANGED
|
@@ -46,7 +46,7 @@ function handleItem(obj, canvasId, api) {
|
|
|
46
46
|
}
|
|
47
47
|
})
|
|
48
48
|
const newObj = [newImgInfo, ...titleInfos, ...newContentInfos]
|
|
49
|
-
const url = await drawImageToCanvas(newObj, canvasId, api)
|
|
49
|
+
const url = await drawImageToCanvas(newObj, canvasId, api, { className: 'share-note-card' })
|
|
50
50
|
resolve(url)
|
|
51
51
|
})
|
|
52
52
|
}
|
|
@@ -90,7 +90,7 @@ function handleItems(arr, canvasId, api) {
|
|
|
90
90
|
newObj.push(newImgInfo, ...titleInfos, ...newContentInfos)
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
const url = await drawImageToCanvas(newObj, canvasId, api)
|
|
93
|
+
const url = await drawImageToCanvas(newObj, canvasId, api, { className: 'share-multi-note-card' })
|
|
94
94
|
resolve(url)
|
|
95
95
|
})
|
|
96
96
|
}
|