Php add centered text to image -
i've tried few times can't seem 2 centered lines of text @ bottom of image on transparent background
any suggestions?
<?php $filepath = "adopt.png"; //full path png, including filename , extension $img = @imagecreatefrompng($filepath); $width = imagesx($img); $height = imagesy($img); //create new image , fill background color $backgroundimg = @imagecreatetruecolor($width, $height); imagecopy($backgroundimg, $img, 0, 0, 0, 0, 100, 130); $color = imagecolorallocatealpha($backgroundimg, 0, 0, 0, 127); //fill transparent imagefill($backgroundimg, 0, 0, $color); //save png header( "content-type: image/png" ); imagepng( $backgroundimg ); imagedestroy( $backgroundimg ); ?>
this process works. without code can regurgitate example manual you. http://php.net/manual/en/function.imagestring.php. works, have used imagestring function. accepts co-ordinates text can not see why not work you.
<?php // create 100*30 image $im = imagecreate(100, 30); // white background , blue text $bg = imagecolorallocate($im, 255, 255, 255); $textcolor = imagecolorallocate($im, 0, 0, 255); // write string @ top left imagestring($im, 5, 0, 0, 'hello world!', $textcolor); // output image header('content-type: image/png'); imagepng($im); imagedestroy($im); ?>
Comments
Post a Comment