Yii Framework Forum: Convert text from your database into an image using ImageMagick - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Convert text from your database into an image using ImageMagick Rate Topic: -----

#1 User is offline   Dhaval Bhavnagari 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 14-December 11

Posted 19 January 2012 - 06:47 AM

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'),
),

0

#2 User is offline   dfsg 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 25-April 13

Posted 26 April 2013 - 03:08 AM

that's brilliant
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users