Skip to content

Commit f2d569f

Browse files
authored
Merge pull request #13 from placeholder-app/amattu2/issue12
Add dynamic font size scaling
2 parents 86171ec + 0a12956 commit f2d569f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@ This is the backend API behind [placeholder.app](https://placeholder.app). See t
66
[![Go Report Card](https://goreportcard.com/badge/github.com/placeholder-app/backend)](https://goreportcard.com/report/github.com/placeholder-app/backend)
77
[![Dependency Review](https://github.com/placeholder-app/backend/actions/workflows/dependency-review.yml/badge.svg)](https://github.com/placeholder-app/backend/actions/workflows/dependency-review.yml)
88

9+
## Examples
10+
11+
Sizes supported are 30px thru 4000px. These are just example sizes with default options.
12+
13+
<details>
14+
<summary>Image Examples</summary>
15+
16+
![img](https://api.placeholder.app/image/30x30)
17+
18+
![img](https://api.placeholder.app/image/70x70)
19+
20+
![img](https://api.placeholder.app/image/120x120)
21+
22+
![img](https://api.placeholder.app/image/160x160)
23+
24+
![img](https://api.placeholder.app/image/200x200)
25+
26+
![img](https://api.placeholder.app/image/245x245)
27+
28+
![img](https://api.placeholder.app/image/310x310)
29+
30+
![img](https://api.placeholder.app/image/450x450)
31+
32+
![img](https://api.placeholder.app/image/650x650)
33+
34+
</details>
35+
936
# Usage
1037

1138
## Setup

shared/customImage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"image/gif"
3131
"image/jpeg"
3232
"image/png"
33+
"math"
3334

3435
"golang.org/x/image/bmp"
3536
"golang.org/x/image/font"
@@ -167,7 +168,7 @@ func (i *CustomImage) Encode(img *image.RGBA) (bytes.Buffer, error) {
167168
func (i *CustomImage) DrawText(img *image.RGBA) {
168169
// Get the font
169170
selectedFont := GetFontStruct(i.FontFamily)
170-
fontface := selectedFont.GetFontFace(78, 32)
171+
fontface := selectedFont.GetFontFace(72, 0.15*math.Min(float64(i.Width), float64(i.Height)))
171172
textData := selectedFont.GetTextData(fontface, i.Text)
172173

173174
// Create the drawer

0 commit comments

Comments
 (0)