Skip to content

huantt/dynamic-thumbnail-service-v2

Repository files navigation

About

License Go Report Card

This is dynamic-thumbnail-service-v2. It's X5 faster compared to the previous version.

In this version, we no longer use Puppeteer (a headless browser) to capture HTML and then return images. Instead, we utilize the @vercel/og library, which employs Satori as its core engine.

(Satori: Enlightened library is used to convert HTML and CSS into SVG))

Usage

Run

Run local

pnpm install
pnpm run dev

Run Docker

docker run -p 3001:3000 huanttok/dynamic-thumbnail-service-v2:latest

Now service is live on http://localhost:3001

Available endpoints

1/ API debug html

GET: /article/thumbnail/html

Params:

  • title: your article title
  • author: author name
  • avatar: avatar url

2/ API thumbnail image

GET: /article/thumbnail/article

Params:

  • title: your article title
  • author: author name
  • avatar: avatar url
  • debug: true/false

Apply to your website

Insert the following meta tag into your website:

<meta property="og:image" content="http://dynamic-thumbnail-service/article/thumbnail?title={TITLE}&author={AUTHOR}&avatar={AVATAR}">

Now, when user share your page to Twitter, Facebook, or Slack chat,... you will see this thumbnail:

Jack dynamic thumbnail

You can use Facebook debug tool to preview.

Customize your own

Satori uses the same Flexbox layout engine as React Native, and it’s not a complete CSS implementation. However, it supports a subset of the spec that covers most common CSS features.

Available CSS features
Property Property Expanded Supported Values Example
display none and flex, default to flex
position relative and absolute, default to relative
color Supported
margin
marginTopSupported
marginRightSupported
marginBottomSupported
marginLeftSupported
Position
topSupported
rightSupported
bottomSupported
leftSupported
Size
widthSupported
heightSupported
Min & max size
minWidthSupported except for min-content and max-content
minHeightSupported except for min-content and max-content
maxWidthSupported except for min-content and max-content
maxHeightSupported except for min-content and max-content
border
Width (borderWidth, borderTopWidth, ...)Supported
Style (borderStyle, borderTopStyle, ...)solid and dashed, default to solid
Color (borderColor, borderTopColor, ...)Supported
Shorthand (border, borderTop, ...)Supported, i.e. 1px solid gray
borderRadius
borderTopLeftRadiusSupported
borderTopRightRadiusSupported
borderBottomLeftRadiusSupported
borderBottomRightRadiusSupported
ShorthandSupported, i.e. 5px, 50% / 5px
Flex
flexDirectioncolumn, row, row-reverse, column-reverse, default to row
flexWrapwrap, nowrap, wrap-reverse, default to wrap
flexGrowSupported
flexShrinkSupported
flexBasisSupported except for auto
alignItemsstretch, center, flex-start, flex-end, baseline, normal, default to stretch
alignContentSupported
alignSelfSupported
justifyContentSupported
gapSupported
Font
fontFamilySupported
fontSizeSupported
fontWeightSupported
fontStyleSupported
Text
tabSizeSupported
textAlignstart, end, left, right, center, justify, default to start
textTransformnone, lowercase, uppercase, capitalize, defaults to none
textOverflowclip, ellipsis, defaults to clip
textDecorationSupport line types underline and line-through, and styles dotted, dashed, solidExample
textShadowSupported
lineHeightSupported
letterSpacingSupported
whiteSpacenormal, pre, pre-wrap, pre-line, nowrap, defaults to normal
wordBreaknormal, break-all, break-word, keep-all, defaults to normal
textWrapwrap, balance, defaults to wrap
Background
backgroundColorSupported, single value
backgroundImagelinear-gradient, radial-gradient, url, single value
backgroundPositionSupport single value
backgroundSizeSupport two-value size i.e. `10px 20%`
backgroundClipborder-box, text
backgroundRepeatrepeat, repeat-x, repeat-y, no-repeat, defaults to repeat
transform
Translate (translate, translateX, translateY)Supported
RotateSupported
Scale (scale, scaleX, scaleY)Supported
Skew (skew, skewX, skewY)Supported
transformOrigin Support one-value and two-value syntax (both relative and absolute values)
objectFit contain, cover, none, default to none
opacity Supported
boxShadow Supported
overflow visible and hidden, default to visible
filter Supported
clipPath Supported Example
lineClamp Supported Example
Mask
maskImagelinear-gradient(...), radial-gradient(...), url(...)Example
maskPositionSupportedExample
maskSizeSupport two-value size i.e. `10px 20%`Example
maskRepeatrepeat, repeat-x, repeat-y, no-repeat, defaults to repeatExample

View up-to-date list here: https://github.com/vercel/satori#css

Libraries

Reference