Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function rotate_square($arr) {
- $fontfile = '/usr/share/fonts/TTF/DejaVuSansMono.ttf';
- $fontsize = 12.0;
- $rowstrs = $rowheights = array();
- $maxwidth = $totalheight = 0;
- foreach ($arr as $row) {
- $rowstrs[] = $rowstr = implode(' ', $row);
- if (($bbox = imagettfbbox($fontsize, 0.0, $fontfile, $rowstr)) !== FALSE) {
- $width = abs($bbox[4] - $bbox[0]);
- if ($width > $maxwidth) $maxwidth = $width;
- $height = abs($bbox[5] - $bbox[1]);
- $rowheights[] = $height;
- $totalheight += $height;
- } else {
- return FALSE;
- }
- }
- $sidelen = max($maxwidth, $totalheight);
- if (($im = imagecreatetruecolor($sidelen, $sidelen)) === FALSE)
- return $im;
- $white = imagecolorallocate($im, 255, 255, 255);
- $black = imagecolorallocate($im, 0, 0, 0);
- imagefilledrectangle($im, 0, 0, $sidelen - 1, $sidelen - 1, $white);
- $i = $totalheight = 0;
- foreach ($arr as $row) {
- imagettftext($im, $fontsize, 0.0, 0, $totalheight, $black, $fontfile, $rowstr[$i]);
- $totalheight += $rowheights[$i];
- $i++;
- }
- $imr = imagerotate($im, 270.0, $white);
- imagedestroy($im);
- return $imr;
- }
- $m = array(array(1, 0, 0),
- array(0, 1, 0),
- array(0, 0, 1));
- $result = rotate_square($m);
- if ($result !== FALSE) {
- header('Content-Type: image/png');
- imagepng($result);
- imagedestroy($result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement