Convert text from your database into an image using ImageMagick

In my quest to complete my task I have come across yet another method to convert text into image. By far I think this is the best. Check it out and let me know what you feel.

For this you will need ImageMagick which can easily downloaded from the net and then installed

In your table controller

I have used my table Categorytable and my column name at which the text is stored is patient_name




public function actionimage()

{

$event=1;

$names = Categorytable::model()->findAll(array(

));

echo '<ol>';

$NameCounter=1;


$font1 ='/home/woi/andalewtj.ttf';

//path to the place where your font is stored


$font  = 35;

foreach($names as $name)

{

$string= $name->patient_name;

 

    $im = new Imagick();




 $pixel = new ImagickPixel( 'orange' );




    $draw = new ImagickDraw();


    

   $draw->setFont ($font1);


   

    $draw->setFontSize( 30 );


     

 

    $text = $string;


  

    $font_info = $im->queryFontMetrics($draw, $text );


   

    $width = $font_info['textWidth'];


  

    $height = $font_info['textHeight'];


    

    $im->newImage($width, $height, $pixel);

 


    $im->annotateImage($draw, 0, 20, 0, $text);


    

    $im->setImageFormat('png');


    

    $im->writeImage( '/home/woi/'.$NameCounter.'text.png' );

$NameCounter++;

$t++;

    echo 'Image Created';

}




Add the following to your index.php in your view folder of your table




array('label'=>'Take An Image','url'=>array('image')),



And change your controller access rules by adding





Hope you like it.

array('allow',

'actions' =>array('admin','image'),

'users' =>array('admin'),

),



that’s brilliant