Hi guys
lately I was trying to export data from mysql into an image. I have got it to work with the following code although with some limitations
here the table is categorytable and the column name is patient_id
add this code into your table controller
/*$names = Categorytable::model()->findAll(array(
));
echo '<ol>';
$NameCounter=1;
$font1 ='/home/woi/arial.ttf';
foreach($names as $name)
{
$string= $name->patient_name;
$font_size = 14;
$ts=explode("\n",$string);
$width=0;
foreach ($ts as $k=>$string) { //compute width
$width=max($width,strlen($string));
}
// Create image width dependant on width of the string
$width = imagefontwidth($font_size)*$width;
// Set height to that of the font
$height = imagefontheight($font_size)*count($ts);
$el=imagefontheight($font_size);
$em=imagefontwidth($font_size);
// Create the image pallette
$img = imagecreatetruecolor($width,$height);
// Dark red background
$bg = imagecolorallocate($img, 0x00, 0x00, 0x00);
imagefilledrectangle($img, 0, 0,$width ,$height , $bg);
// White font color
$color = imagecolorallocate($img, 255, 255, 255);
foreach ($ts as $k=>$string) {
// Length of the string
$len = strlen($string);
// Loop through the string
for($i=0;$i<$len;$i++){
// Draw character
imagestring($img, $font_size, 0, 0, $line, $color);
}
imagejpeg($img,'/home/woi/'.$NameCounter.'i.jpeg');
$NameCounter++;
// Remove image
imagedestroy($img)
}*/
}
add this little line to your views where you want the button
I added it to my create.php file in the table folder
array(‘label’=>‘Take An Image’,‘url’=>array(‘index’)),
Don’t forget to change the rules in the controller file
Limitaions
The above code works fine for single line texts but does not identify line breaks.
I am still working on it and any help will be appreciated.