Wednesday, March 18

Converting Text to Image using php, command script.



This example script will produce a white PNG , with the words "This is a TEXT!!!" in black, in the font Serif.

<?php  
    //Font Family
    $font_family = 'Serif';
  
    //Color of the font
    $color = 'rgb(0,0,0)';
  
    //Size of the font
    $font_size = intval(substr('14px', 0, -2));
  
    //The Text to make image
    $text = 'This is a TEXT!!!';
  
    //Rotate the text in degree
    $arc = 0;
  
    //File path
    $file_path = dirname(__FILE__).'/temp.png';
  
    $command="convert -background none -font '$font_family' -fill '$color' -pointsize $font_size label:' $text ' \
          -virtual-pixel Background  -background none \
          -distort Arc ".$arc."   $file_path";
  
    //To excute commands
    exec($command);

    if (file_exists($filepath)) {
       echo '<img src="'.$save_temp_dir.$filename.'" />';
    } 
?>

No comments:

Post a Comment