Skip to content

Commit 78b5f1b

Browse files
committed
fix: image text options
1 parent 2323d7e commit 78b5f1b

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ export interface ImagePlaceholderOptions {
186186
*
187187
* 或者传入一组颜色数组,将会随机选择任意颜色作为默认背景色
188188
*
189-
* @default '#ccc'
189+
* @default '#efefef'
190190
*
191191
*/
192192
background?: string | string[]
193193
/**
194194
* 文本默认颜色, `Hex` 或者 `RGB` 格式的值
195195
*
196-
* @default '#333'
196+
* @default '#666'
197197
*/
198198
textColor?: string
199199
/**

example/index.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
<img src="/image/placeholder/text/人生如梦.png" alt="">
2525
<img src="/image/placeholder/bg/00ffcc/text/youcan.webp" alt="">
2626
<img src="/image/placeholder/text/i can/bg/ccffcc.jpeg" alt="">
27-
<img src="/image/placeholder/text/人生如梦/300/200?noise=1&textColor=red" alt="">
28-
<img src="/image/placeholder/text/人生如梦/300/200?noise=1&textColor=255,255,255" alt="">
29-
<img src="/image/placeholder/text/人生如梦/300/200?noise=1&textColor=rgb(110,110,110,0.2)" alt="">
30-
<img src="/image/placeholder/text/人生如梦/300/200?noise=1&textColor=255,255,255,.8" alt="">
27+
<img src="/image/placeholder/text/人生如梦red/textColor/255,0,0/300/200?noise=1" alt="">
28+
<img src="/image/placeholder/text/人生如梦/textColor/255,255,255/300/200?noise=1" alt="">
29+
<img src="/image/placeholder/text/人生如梦/textColor/rgb(110,110,110,0.2)/300/200?noise=1" alt="">
30+
<img src="/image/placeholder/text/人生如梦/textColor/255,255,255,.8/300/200?noise=1" alt="">
3131
<img src="/image/placeholder/text/gif/300.gif" alt="">
3232
<img src="/image/placeholder/text/webp/300.webp" alt="">
3333
<img src="/image/placeholder/text/avif/300.avif" alt="">
3434
<img src="/image/placeholder/text/heif/300.heif" alt="">
3535
<img src="/image/placeholder/1.gif" alt="">
3636
<img src="/image/placeholder/text/svg/300.svg" alt="">
37-
<img src="/image/placeholder/text/image-placeholder/bg/09c.svg?textColor=fff" alt="">
37+
<img src="/image/placeholder/text/image-placeholder/bg/09c/c/fff.svg" alt="">
3838
<script type="module" src="./main.ts"></script>
3939
</body>
4040
</html>

src/pathToImage.ts

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export async function pathToImage(
6363
const textOptions: TextOptions = {
6464
dpi: Math.floor((Math.min(width, height) / 4) * 3) || 1,
6565
text: params.text || options.text || `${width}x${height}`,
66+
font: 'Menlo, Monaco, "Courier New", monospace',
6667
rgba: true,
6768
}
6869

src/plugin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export const parseOptions = (
1515
options = Object.assign(
1616
{
1717
prefix: 'image/placeholder',
18-
background: '#ccc',
19-
textColor: '#333',
18+
background: '#efefef',
19+
textColor: '#666',
2020
width: 300,
2121
type: 'png',
2222
quality: 80,

src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const formatColor = (
4545
}
4646

4747
export const formatText = (text: string, color: string) => {
48-
return `<span font-family="monospace" foreground="${color}">${text}</span>`
48+
return `<span foreground="${color}">${text}</span>`
4949
}
5050

5151
export const getMimeType = (type: ImageType = 'png'): string => {

0 commit comments

Comments
 (0)