Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- convert -font 'tahoma.ttf' -draw "text 10,10 'the text'" img.png
- // Set font.
- $font = PATH/TO/YOUR/CUSTOM/FONT
- // Get dimensions.
- // Create a new Imagick object.
- $imTest = new Imagick();
- // Create an ImagickDraw object.
- $drawTest = new ImagickDraw();
- // Set the font.
- $drawTest->setFont($font);
- // Set the local X and Y.
- $localX = 0;
- $localY = 0;
- // Dump the font metrics, autodetect multiline
- for ($i = 0; $i < strlen($yourText); $i++) {
- if ($yourText[$i] === ' ') {
- $tempX += $imTest->queryFontMetrics($drawTest, $yourText[$i])['textWidth'];
- } else {
- $tempX += $imTest->queryFontMetrics($drawTest, $yourText[$i])['originX'] + $imTest->queryFontMetrics($drawTest, $yourText[$i])['boundingBox']['x2'] + $imTest->queryFontMetrics($drawTest, $yourText[$i])['boundingBox']['x1'];
- }
- }
- // Generate image.
- $cmd = 'convert -size ' . $localX . 'x' . $maxY . ' xc:none -gravity Center -font ' . $font . ' -pointsize ' . $fontSize . ' -annotate +0+0 "' . $yourText . '" ' . FINAL/PATH/TO/YOUR/FILE.png';
- $r = shell_exec($cmd);
Add Comment
Please, Sign In to add comment