Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Set content type to PNG
- header('Content-Type: image/png');
- // Create an image with specified dimensions
- $width = 400;
- $height = 200;
- $image = imagecreatetruecolor($width, $height);
- // Allocate colors
- $white = imagecolorallocate($image, 255, 255, 255);
- $black = imagecolorallocate($image, 0, 0, 0);
- // Fill the background with white
- imagefilledrectangle($image, 0, 0, $width, $height, $white);
- // Define the text to render
- $text = "Rotated Text";
- // Set font size and path (make sure the font file exists on your server)
- $font_size = 20;
- $font_path = './DejaVuSans.ttf'; // Replace with the path to your font file
- $angle = 90;
- // Calculate the bounding box of the text
- $bbox = imagettfbbox($font_size, $angle, $font_path, $text);
- // Determine text width and height from the bounding box
- $text_width = abs($bbox[4] - $bbox[0]);
- $text_height = abs($bbox[5] - $bbox[1]);
- // Calculate the position to center the text in the image
- $x = ($width - $text_width) / 2;
- $y = ($height + $text_height) / 2;
- // Render the rotated text
- imagettftext($image, $font_size, $angle, $x, $y, $black, $font_path, $text);
- // Output the image as a PNG
- imagepng($image);
- // Free memory
- imagedestroy($image);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement