Devesh Kumar No comments

How to convert text to image in php

 



There are two solutions for it, using TextToImage_my method which can be generated auto-sized output an next will be customized.

Solution 1 (auto-sized output):


<?php
TextToImage_my( $text='Hello PHP');
?>


Solution 2 (manual-sized output):


<?php
$text = "Hello PHP";

$my_img = imagecreate( 200, 80 );                             //width & height
$background  = imagecolorallocate( $my_img, 0,   0,   255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
imagestring( $my_img, 4, 30, 25, $text, $text_colour );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, $line_colour );

header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
?>


Comments (0)

Post a Comment

Cancel