• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Question Need a API-Text to Image PHP script

Bluscream

Former Team
Contributor
#1
Hey guys, i was thinking of this a lot of times now and most of you seem pretty familiar with PHP and webservers so i decided to explain my request here as good as possible:

How it should work:
  1. I copy the script template and rewrite it to use the API i need right now ( In this example the github API )
  2. I upload it to my webserver at for example
    You do not have permission to view link Log in or register now.
  3. Anyone can request
    You do not have permission to view link Log in or register now.
  4. It returns the text returned by the api in a white color on the image.
It would be awesome if someone could point me to it if it already exists :)
 

Kleberstoff

Knowledge Seeker
#2
So basicly, you want a script that outputs the API's output to a Image and the Image Color can be changed by a get-request?
Just need confirmation that i understood it correctly.
 

Norvik

Former Team
Contributor
#3
Hey guys, i was thinking of this a lot of times now and most of you seem pretty familiar with PHP and webservers so i decided to explain my request here as good as possible:

How it should work:
  1. I copy the script template and rewrite it to use the API i need right now ( In this example the github API )
  2. I upload it to my webserver at for example
    You do not have permission to view link Log in or register now.
  3. Anyone can request
    You do not have permission to view link Log in or register now.
  4. It returns the text returned by the api in a white color on the image.
It would be awesome if someone could point me to it if it already exists :)
I'm gonna work on it as soon as I'm at home. It's not that hard, do you want it to be a png or a jpg file?
 
#6
PHP:
function makeImageF($text, $W=800, $fsize=13,$bgr=1,$bgb=1,$bgg=1,$bga=127){
      $H = substr_count ($text,"\n") * 20;
       //$H = 50;
      
    $im = imagecreatetruecolor($W, $H);
       imagesavealpha($im, true);
    $background_color = imagecolorallocatealpha ($im, $bgr,$bgb,$bgg,$bga);        //RGB color background.
    imagefill ($im,0,0,$background_color);
       $text_color = imagecolorallocate($im, 0, 0, 0);
      
       $i = 0;
       putenv('GDFONTPATH=' . realpath('.'));
       foreach (explode("\n" , $text) as $value){
           imagettftext ($im , $fsize ,0, 0 , ($i * 16)+16, $text_color, dirname(__FILE__) . '/cour.ttf',$value);
           //array imagettftext ( resource $im , int $size , int $angle , int $x , int $y , int $col , string $fontfile , string $text )
           // imagestring($im, 1, 0, $i * 20, $value,$text_color);
           $i+=1;
       }
          
          
  
    
    header('Content-type: image/png');//jpeg
    //imagejpeg($im);
    imagepng($im);
    imagedestroy($im);
    return;
}
copy pasta from my dynamic teamspeak banner thingy