uni-canvas-image 1.1.2 → 1.1.4
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 +3 -3
- package/src/util/attractImage.js +10 -10
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 = {
|
|
@@ -47,10 +46,11 @@ export async function base64ToBlob(base64Data) {
|
|
|
47
46
|
return await response.blob()
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
export async function drawImageToCanvas(arr, canvasId = 'canvas-1', api) {
|
|
49
|
+
export async function drawImageToCanvas(arr, canvasId = 'canvas-1', api, config) {
|
|
51
50
|
return new Promise((resolve, reject) => {
|
|
51
|
+
const { bgc = '#fff' } = config || {}
|
|
52
52
|
const ctx = uni.createCanvasContext(canvasId)
|
|
53
|
-
ctx.setFillStyle(
|
|
53
|
+
ctx.setFillStyle(bgc)
|
|
54
54
|
ctx.fillRect(0, 0, 375, 300)
|
|
55
55
|
arr.forEach((item) => {
|
|
56
56
|
if (item.type === 'image') {
|
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)
|
|
36
|
+
const url = await drawImageToCanvas(newObj, canvasId, api, { bgc: '#f2f2f2' })
|
|
37
37
|
resolve(url)
|
|
38
38
|
})
|
|
39
39
|
}
|