@@ -19,6 +19,7 @@ const hexToRgb = (hex: string): [number, number, number] => {
1919export default function App ( ) {
2020 const DEFAULT_TEXT_SIZE = 120 ;
2121 const DEFAULT_BG_DIM = 0.4 ;
22+ const DEFAULT_TEXT_PADDING = 0.05 ;
2223
2324 const camvasSizes : Record <
2425 "cover" | "poster" ,
@@ -47,6 +48,7 @@ export default function App() {
4748 const [ dimColor , setDimColor ] = useState ( "#000000" ) ;
4849 const [ textAlign , setTextAlign ] = useState < TextAlign > ( "center" ) ;
4950 const [ textBaseline , setTextBaseline ] = useState < TextBaseLine > ( "middle" ) ;
51+ const [ textPadding , setTextPadding ] = useState ( DEFAULT_TEXT_PADDING ) ;
5052
5153 const getCanvasWidth = ( ) => camvasSizes [ imageType ] . width ;
5254 const getCanvasHeight = ( ) => camvasSizes [ imageType ] . height ;
@@ -75,8 +77,9 @@ export default function App() {
7577 ctx . textAlign = align ;
7678
7779 let x : number = getCanvasWidth ( ) / 2 ;
78- if ( align === "left" ) x = maxWidth * 0.05 ;
79- else if ( align === "right" ) x = getCanvasWidth ( ) - maxWidth * 0.05 ;
80+ if ( align === "left" ) x = maxWidth * textPadding ;
81+ else if ( align === "right" )
82+ x = getCanvasWidth ( ) - maxWidth * textPadding ;
8083
8184 const words = text . split ( " " ) ;
8285 const lines : string [ ] = [ ] ;
@@ -96,7 +99,7 @@ export default function App() {
9699
97100 const totalHeight = lines . length * lineHeight ;
98101
99- const padding = getCanvasHeight ( ) * 0.05 ;
102+ const padding = getCanvasHeight ( ) * textPadding ;
100103 let y : number ;
101104 if ( baseline === "top" ) {
102105 y = padding ;
@@ -208,6 +211,7 @@ export default function App() {
208211 dimColor ,
209212 textAlign ,
210213 textBaseline ,
214+ textPadding ,
211215 ] ) ;
212216
213217 useEffect ( ( ) => {
@@ -264,6 +268,9 @@ export default function App() {
264268 setTextAlign = { setTextAlign }
265269 textBaseline = { textBaseline }
266270 setTextBaseline = { setTextBaseline }
271+ defaultTextPadding = { DEFAULT_TEXT_PADDING }
272+ textPadding = { textPadding }
273+ setTextPadding = { setTextPadding }
267274 />
268275
269276 < div
0 commit comments