Need a API-Text to Image PHP script

Bluscream

Retired Staff
Contributor
May 8, 2015
967
934
211
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 https://example.com/banner/github.php
  3. Anyone can request https://example.com/banner/github.p...://example.com/banner/image.php&color=#ffffff
  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
VIP
Dec 29, 2015
308
214
158
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

Retired Staff
Contributor
Jul 18, 2015
635
588
157
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 https://example.com/banner/github.php
  3. Anyone can request https://example.com/banner/github.p...://example.com/banner/image.php&color=#ffffff
  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?
 

Bluscream

Retired Staff
Contributor
May 8, 2015
967
934
211
Thanks, i would prefer a png for transparency ♥
 

dedmen

TeamSpeak Developer
Contributor
Mar 28, 2016
530
583
157
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
 
Top