@azuro-org/images-generator 0.0.5 → 1.0.2

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/README.md CHANGED
@@ -4,25 +4,10 @@
4
4
 
5
5
  ```typescript
6
6
  import { generateImage } from '@azuro-org/images-generator';
7
- import template, { type Props } from '@azuro-org/images-generator/dist/templates/bet-nft';
7
+ import template, { type Props } from '@azuro-org/images-generator/lib/templates/bet-nft';
8
8
 
9
9
  const props: Props = {
10
- type: 'match',
11
- sport: 'soccer',
12
- league: 'Leinster Senior League Senior Division',
13
- team1: {
14
- img: 'https://content.bookieratings.net/images/fq/tx/fqtxnf_20181001112329_100x100.png',
15
- name: 'Nizhny Novgorod'
16
- },
17
- team2: {
18
- img: 'https://content.bookieratings.net/images/fq/tx/fqtxnf_20181001112329_100x100.png',
19
- name: 'Lokomotiv Moscow'
20
- },
21
- date: '21.03.2022 8:00 UTC',
22
- betAmount: '100 USDC',
23
- outcome: 'Total Under(2.5)',
24
- betOdds: '2.88',
25
- currentOdds: '1.88'
10
+ // ...
26
11
  }
27
12
 
28
13
  // get image buffer
@@ -41,7 +26,7 @@ generateImage({
41
26
 
42
27
  ## Options
43
28
 
44
- ```
29
+ ```typescript
45
30
  type PuppeteerOptions = Parameters<typeof puppeteer.launch>[0]
46
31
 
47
32
  type PuppeteerInitialOptions = {
@@ -59,6 +44,112 @@ generateImage({
59
44
  ```
60
45
 
61
46
 
47
+ # Examples
48
+
49
+ <details>
50
+ <summary><h3>Bet Opengraph</h3></summary>
51
+ <p>
52
+
53
+ ```typescript
54
+ import { generateImage } from '@azuro-org/images-generator';
55
+ import template from '@azuro-org/images-generator/lib/templates/bet-og';
56
+
57
+ generateImage({
58
+ template,
59
+ props: {
60
+ title: 'Decentralized betting is awesome!',
61
+ game: {
62
+ country: 'International Tournaments',
63
+ league: 'ESL Challenger League North America',
64
+ participants: [
65
+ {
66
+ name: 'WINDINGO',
67
+ image: 'https://content.bookmaker.xyz/avatars/provider-3/4757.png',
68
+ },
69
+ {
70
+ name: 'Los Grandes Academy',
71
+ image: 'https://content.bookmaker.xyz/avatars/provider-3/4739.png',
72
+ },
73
+ ],
74
+ startsAt: Date.now(),
75
+ }
76
+ },
77
+ })
78
+ ```
79
+
80
+ ### Result
81
+
82
+ <p>
83
+ <img src="./src/templates/bet-og/example.jpeg" width="600" />
84
+ </p>
85
+ </p>
86
+ </details>
87
+
88
+ <details>
89
+ <summary><h3>Bet NFT</h3></summary>
90
+ <p>
91
+
92
+ ```typescript
93
+ import { generateImage } from '@azuro-org/images-generator';
94
+ import template from '@azuro-org/images-generator/lib/templates/bet-nft';
95
+
96
+ generateImage({
97
+ template,
98
+ props: {
99
+ type: 'match',
100
+ sport: 'Football',
101
+ league: 'International Tournaments · FIFA - World Cup',
102
+ team1: {
103
+ img: 'https://content.bookmaker.xyz/avatars/provider-3/4757.png',
104
+ name: 'Ecuador',
105
+ },
106
+ team2: {
107
+ img: 'https://content.bookmaker.xyz/avatars/provider-3/4739.png',
108
+ name: 'Senegal',
109
+ },
110
+ date: 'Dec 24, 2020',
111
+ betAmount: '100 xDAI',
112
+ outcome: 'Senegal',
113
+ betOdds: '1.7',
114
+ currentOdds: '1.2',
115
+ },
116
+ })
117
+ ```
118
+
119
+ ### Result
120
+
121
+ <p>
122
+ <img src="./src/templates/bet-nft/example.png" width="255" />
123
+ </p>
124
+ </p>
125
+ </details>
126
+
127
+ <details>
128
+ <summary><h3>Bet Opengraph</h3></summary>
129
+ <p>
130
+
131
+ ```typescript
132
+ import { generateImage } from '@azuro-org/images-generator';
133
+ import template from '@azuro-org/images-generator/lib/templates/freebet';
134
+
135
+ generateImage({
136
+ template,
137
+ props: {
138
+ amount: 5,
139
+ date: '12.01.2022',
140
+ },
141
+ })
142
+ ```
143
+
144
+ ### Result
145
+
146
+ <p>
147
+ <img src="./src/templates/freebet/example.png" width="416" />
148
+ </p>
149
+ </p>
150
+ </details>
151
+
152
+
62
153
  # Contributing
63
154
 
64
155
  ## Add new template
@@ -73,6 +164,8 @@ generateImage({
73
164
  Edit `{your_template_name}/index.ts` file:
74
165
 
75
166
  ```typescript
167
+ import path from 'path'
168
+
76
169
  import { type Template, getFile, downloadImage, createGenerator } from '../../utils'
77
170
 
78
171
  export type Props = {
@@ -88,14 +181,12 @@ const template = {
88
181
  html: async (props: Props) => {
89
182
  const { team1ImageSrc, team2ImageSrc, date } = props
90
183
 
91
- let html = getFile('./index.html')
92
- let css = getFile('./index.css')
184
+ const html = getFile(path.join(__dirname, 'index.html'))
93
185
 
94
186
  const team1Img = await downloadImage(team1ImageSrc)
95
187
  const team2Img = await downloadImage(team2ImageSrc)
96
188
 
97
189
  return html
98
- .replace('.style{}', css)
99
190
  .replace('{image1}', team1Img)
100
191
  .replace('{image2}', team2Img)
101
192
  .replace('{date}', date)
@@ -105,14 +196,6 @@ const template = {
105
196
  export default template
106
197
  ```
107
198
 
108
-
109
- ## `createGenerator` options
110
-
111
- `type: 'png' | 'jpeg'`<br /><br />
112
- `headless: Boolean` - use true to see compiled html in browser<br /><br />
113
- `scaleFactor: 1 | 2` - use 2 if you need to generate x2 sized image
114
-
115
-
116
199
  ## Publish
117
200
 
118
201
  Publish npm package with `npm run publish`. For access to `@azuro-org` scope ask Pavel Ivanov or Stas Onatskiy.
@@ -0,0 +1,7 @@
1
+ import { type Template } from '../../utils';
2
+ export type Props = {
3
+ amount: number | string;
4
+ date: string;
5
+ };
6
+ declare const template: Template;
7
+ export default template;
@@ -0,0 +1,62 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <link href="//raw.githubusercontent.com/Azuro-protocol/public-assets/main/fonts/fivo-sans-modern/style.css" rel="stylesheet" />
7
+ <style>
8
+ html, body {
9
+ width: 416px;
10
+ height: 250px;
11
+ margin: 0;
12
+ padding: 0;
13
+ }
14
+
15
+ .image {
16
+ width: 416px;
17
+ height: 250px;
18
+ padding-top: 75px;
19
+ padding-left: 30px;
20
+ font-family: 'Fivo Sans Modern';
21
+ font-weight: 700;
22
+ background-size: cover;
23
+ background-position: center;
24
+ overflow: hidden;
25
+ border-radius: 10px;
26
+ }
27
+
28
+ .amount {
29
+ font-size: 48px;
30
+ line-height: 50px;
31
+ }
32
+
33
+ .text-gradient {
34
+ background: linear-gradient(271.45deg, #FCBD89 -22.37%, #B78EFF 34.63%, #82FCF4 117.18%), #FFFFFF;
35
+ -webkit-background-clip: text;
36
+ -webkit-text-fill-color: transparent;
37
+ background-clip: text;
38
+ text-fill-color: transparent;
39
+ }
40
+
41
+ .amount span {
42
+ color: #fff;
43
+ }
44
+
45
+ .date {
46
+ margin-top: 8px;
47
+ font-size: 16px;
48
+ line-height: 110%;
49
+ color: #6EE0A3;
50
+ }
51
+ </style>
52
+ </head>
53
+ <body>
54
+ <div class="image" style="background-image: url({bgImage});">
55
+ <div class="amount">
56
+ <div class="text-gradient">{amount} xDAI</div>
57
+ <span>freebet!</span>
58
+ </div>
59
+ <div class="date">Valid until {date}</div>
60
+ </div>
61
+ </body>
62
+ </html>
@@ -0,0 +1,18 @@
1
+ import {_ as __awaiter,a as __generator,g as getFile,b as getBase64Image}from'../../index-401c8546.js';import path from'path';import'fs';import'http';import'https';import'url';import'stream';import'assert';import'tty';import'util';import'os';import'zlib';var template = {
2
+ width: 416,
3
+ height: 250,
4
+ type: 'png',
5
+ scaleFactor: 2,
6
+ html: function (props) { return __awaiter(void 0, void 0, void 0, function () {
7
+ var amount, date, html, bgImage;
8
+ return __generator(this, function (_a) {
9
+ amount = props.amount, date = props.date;
10
+ html = getFile(path.resolve(__dirname, 'index.html'));
11
+ bgImage = getBase64Image(path.resolve(__dirname, 'images/bg.png'));
12
+ return [2 /*return*/, html
13
+ .replace('{bgImage}', bgImage)
14
+ .replace('{amount}', String(amount))
15
+ .replace('{date}', date)];
16
+ });
17
+ }); }
18
+ };export{template as default};
@@ -0,0 +1,7 @@
1
+ import { type Template } from '../../utils';
2
+ export type Props = {
3
+ amount: number | string;
4
+ date: string;
5
+ };
6
+ declare const template: Template;
7
+ export default template;
@@ -0,0 +1,62 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <link href="//raw.githubusercontent.com/Azuro-protocol/public-assets/main/fonts/fivo-sans-modern/style.css" rel="stylesheet" />
7
+ <style>
8
+ html, body {
9
+ width: 416px;
10
+ height: 250px;
11
+ margin: 0;
12
+ padding: 0;
13
+ }
14
+
15
+ .image {
16
+ width: 416px;
17
+ height: 250px;
18
+ padding-top: 75px;
19
+ padding-left: 30px;
20
+ font-family: 'Fivo Sans Modern';
21
+ font-weight: 700;
22
+ background-size: cover;
23
+ background-position: center;
24
+ overflow: hidden;
25
+ border-radius: 10px;
26
+ }
27
+
28
+ .amount {
29
+ font-size: 48px;
30
+ line-height: 50px;
31
+ }
32
+
33
+ .text-gradient {
34
+ background: linear-gradient(271.45deg, #FCBD89 -22.37%, #B78EFF 34.63%, #82FCF4 117.18%), #FFFFFF;
35
+ -webkit-background-clip: text;
36
+ -webkit-text-fill-color: transparent;
37
+ background-clip: text;
38
+ text-fill-color: transparent;
39
+ }
40
+
41
+ .amount span {
42
+ color: #fff;
43
+ }
44
+
45
+ .date {
46
+ margin-top: 8px;
47
+ font-size: 16px;
48
+ line-height: 110%;
49
+ color: #6EE0A3;
50
+ }
51
+ </style>
52
+ </head>
53
+ <body>
54
+ <div class="image" style="background-image: url({bgImage});">
55
+ <div class="amount">
56
+ <div class="text-gradient">{amount} xDAI</div>
57
+ <span>freebet!</span>
58
+ </div>
59
+ <div class="date">Valid until {date}</div>
60
+ </div>
61
+ </body>
62
+ </html>
@@ -0,0 +1,18 @@
1
+ 'use strict';var index=require('../../index-7f0cb09b.js'),path=require('path');require('fs'),require('http'),require('https'),require('url'),require('stream'),require('assert'),require('tty'),require('util'),require('os'),require('zlib');function _interopDefaultLegacy(e){return e&&typeof e==='object'&&'default'in e?e:{'default':e}}var path__default=/*#__PURE__*/_interopDefaultLegacy(path);var template = {
2
+ width: 416,
3
+ height: 250,
4
+ type: 'png',
5
+ scaleFactor: 2,
6
+ html: function (props) { return index._(void 0, void 0, void 0, function () {
7
+ var amount, date, html, bgImage;
8
+ return index.a(this, function (_a) {
9
+ amount = props.amount, date = props.date;
10
+ html = index.g(path__default["default"].resolve(__dirname, 'index.html'));
11
+ bgImage = index.b(path__default["default"].resolve(__dirname, 'images/bg.png'));
12
+ return [2 /*return*/, html
13
+ .replace('{bgImage}', bgImage)
14
+ .replace('{amount}', String(amount))
15
+ .replace('{date}', date)];
16
+ });
17
+ }); }
18
+ };module.exports=template;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azuro-org/images-generator",
3
- "version": "0.0.5",
3
+ "version": "1.0.2",
4
4
  "license": "ISC",
5
5
  "engines": {
6
6
  "node": "=16.15.1",