Skip to content

Commit

Permalink
#12 Add dynamic font size scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
amattu2 committed Feb 8, 2023
1 parent 6cb3157 commit 0a12956
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ This is the backend API behind [placeholder.app](https://placeholder.app). See t
[![Go Report Card](https://goreportcard.com/badge/github.com/placeholder-app/backend)](https://goreportcard.com/report/github.com/placeholder-app/backend)
[![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)

## Examples

Sizes supported are 30px thru 4000px. These are just example sizes with default options.

<details>
<summary>Image Examples</summary>

![img](https://api.placeholder.app/image/30x30)

![img](https://api.placeholder.app/image/70x70)

![img](https://api.placeholder.app/image/120x120)

![img](https://api.placeholder.app/image/160x160)

![img](https://api.placeholder.app/image/200x200)

![img](https://api.placeholder.app/image/245x245)

![img](https://api.placeholder.app/image/310x310)

![img](https://api.placeholder.app/image/450x450)

![img](https://api.placeholder.app/image/650x650)

</details>

# Usage

## Setup
Expand Down
3 changes: 2 additions & 1 deletion shared/customImage.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"image/gif"
"image/jpeg"
"image/png"
"math"

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

// Create the drawer
Expand Down

0 comments on commit 0a12956

Please sign in to comment.