Artykuły na każdy temat
[PHP][GD] Centrowanie napisu w poziomie i pionie
<?php
// Config
$config['width'] = 559;
$config['height'] = 50;
$config['font_size'] = 3;
$config['text'] = 'CapaciousCore';
// Create a image
$im = imagecreate($config['width'], $config['height']);
// Colors
$tmp['color']['background'] = imagecolorallocate($im, 255, 255, 255);
$tmp['color']['border'] = imagecolorallocate($im, 238, 241, 242);
$tmp['color']['text'] = imagecolorallocate($im, 255, 0, 0);
// Draw the border
imagerectangle($im, 0, 0, $config['width'] - 1, $config['height'] - 1, $tmp['color']['border']);
// Calculate the font size
$tmp['font']['width'] = imagefontwidth($config['font_size']);
$tmp['font']['height'] = imagefontheight($config['font_size']);
// Calculate the position
$tmp['position']['center'] = ceil(($config['width'] - $tmp['font']['width'] * strlen($config['text'])) / 2);
$tmp['position']['middle'] = ceil(($config['height'] - $tmp['font']['height']) / 2);
// Write the string
imagestring($im, $config['font_size'], $tmp['position']['center'], $tmp['position']['middle'], $config['text'], $tmp['color']['text']);
// Output image
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
Komentarze
Dodaj komentarz
Mister Klikacz