Guest User

Untitled

a guest
Nov 22nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. convert -font 'tahoma.ttf' -draw "text 10,10 'the text'" img.png
  2.  
  3. // Set font.
  4. $font = PATH/TO/YOUR/CUSTOM/FONT
  5. // Get dimensions.
  6. // Create a new Imagick object.
  7. $imTest = new Imagick();
  8.  
  9. // Create an ImagickDraw object.
  10. $drawTest = new ImagickDraw();
  11.  
  12. // Set the font.
  13. $drawTest->setFont($font);
  14.  
  15. // Set the local X and Y.
  16. $localX = 0;
  17. $localY = 0;
  18.  
  19. // Dump the font metrics, autodetect multiline
  20. for ($i = 0; $i < strlen($yourText); $i++) {
  21. if ($yourText[$i] === ' ') {
  22. $tempX += $imTest->queryFontMetrics($drawTest, $yourText[$i])['textWidth'];
  23. } else {
  24. $tempX += $imTest->queryFontMetrics($drawTest, $yourText[$i])['originX'] + $imTest->queryFontMetrics($drawTest, $yourText[$i])['boundingBox']['x2'] + $imTest->queryFontMetrics($drawTest, $yourText[$i])['boundingBox']['x1'];
  25. }
  26. }
  27.  
  28. // Generate image.
  29. $cmd = 'convert -size ' . $localX . 'x' . $maxY . ' xc:none -gravity Center -font ' . $font . ' -pointsize ' . $fontSize . ' -annotate +0+0 "' . $yourText . '" ' . FINAL/PATH/TO/YOUR/FILE.png';
  30. $r = shell_exec($cmd);
Add Comment
Please, Sign In to add comment