Hi guys, I'm trying to create a picture with GD and PHP. Frankly, the result is so-so. The image is in fact created with specified height and width, BUT it's completely black! Anybody has any idea what the problem might be? Thanks.
And yes, all functions I'm using have been declared prior to the code below.
Code: Select all
<?php
$im = imagecreatetruecolor(100, 100);
header('Content-type: image/png');
$split_hex_bg = str_split(str_replace('#','', $_POST['hexbg']),2);
$split_hex_txt = str_split(str_replace('#','', $_POST['hexbg]),2);
$bg_color = imagecolorallocate($im, str_pad($split_hex_bg[0], 4, '0x', STR_PAD_LEFT), str_pad($split_hex_bg[1], 4, '0x', STR_PAD_LEFT), str_pad($split_hex_bg[2], 4, '0x', STR_PAD_LEFT));
$txt_color = imagecolorallocate($im, str_pad($split_hex_txt[0], 4, '0x', STR_PAD_LEFT), str_pad($split_hex_txt[1], 4, '0x', STR_PAD_LEFT), str_pad($split_hex_txt[2], 4, '0x', STR_PAD_LEFT));
imagefill($im, 0, 0, $bg_color);
$font = 'fonts/arial.TTF';
$txt_artist = str_cut(wordwrap($_POST['artist'], 10), 20);
$txt_album = str_cut(wordwrap($_POST['album'], 10), 17);
imagettftext($im, 11, 0, 10, 22, $txt_color, $font, $txt_artist);
imagettftext($im, 11, 0, 10, 70, $txt_color, $font, $txt_album);
imagepng($im, '../images/infoimgs/info-'.filename($_POST['artist']).'-'.filename($_POST['album']).'.png');
imagedestroy($im);
?>
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: