Advertisement
Guest User

Untitled

a guest
Sep 13th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <?php
  2. // Set content type to PNG
  3. header('Content-Type: image/png');
  4.  
  5. // Create an image with specified dimensions
  6. $width = 400;
  7. $height = 200;
  8. $image = imagecreatetruecolor($width, $height);
  9.  
  10. // Allocate colors
  11. $white = imagecolorallocate($image, 255, 255, 255);
  12. $black = imagecolorallocate($image, 0, 0, 0);
  13.  
  14. // Fill the background with white
  15. imagefilledrectangle($image, 0, 0, $width, $height, $white);
  16.  
  17. // Define the text to render
  18. $text = "Rotated Text";
  19.  
  20. // Set font size and path (make sure the font file exists on your server)
  21. $font_size = 20;
  22. $font_path = './DejaVuSans.ttf'; // Replace with the path to your font file
  23. $angle = 90;
  24.  
  25. // Calculate the bounding box of the text
  26. $bbox = imagettfbbox($font_size, $angle, $font_path, $text);
  27.  
  28. // Determine text width and height from the bounding box
  29. $text_width = abs($bbox[4] - $bbox[0]);
  30. $text_height = abs($bbox[5] - $bbox[1]);
  31.  
  32. // Calculate the position to center the text in the image
  33. $x = ($width - $text_width) / 2;
  34. $y = ($height + $text_height) / 2;
  35.  
  36. // Render the rotated text
  37. imagettftext($image, $font_size, $angle, $x, $y, $black, $font_path, $text);
  38.  
  39. // Output the image as a PNG
  40. imagepng($image);
  41.  
  42. // Free memory
  43. imagedestroy($image);
  44. ?>
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement