turt2live

Untitled

Jan 5th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <?php
  2. include "inc.php";
  3. /* Description Generation:
  4.  *      Generates a description based on a plugin name in the
  5.  *      form of a PNG image. Also shows version number.
  6.  */
  7. $plugin = "";
  8. if(isset($_GET['plugin'])){
  9.     $plugin = $_GET['plugin'];
  10. }
  11. $file = "plugin_".$plugin."/docs/image.txt";
  12. $fh = fopen($file, 'r');
  13. $lines = 0;
  14. $chars = 0;
  15. while($line = fgets($fh)){
  16.     $lines ++;
  17.     if(strlen($line)>$chars){
  18.         $chars = strlen($line);
  19.     }
  20. }
  21. fclose($fh);
  22. $errorFlag = "";
  23. if($lines == 0){
  24.     $lines = 1;
  25.     $errorFlag = "Plugin not found!";
  26. }
  27. $lineheight = 22;
  28. $charwidth = 8;
  29. $img = imagecreate($chars*$charwidth,$lines*$lineheight);
  30. $backgroundcolor = imagecolorallocate($img, 255, 255, 255);
  31. $text_colour = imagecolorallocate($img, 0, 0, 0);
  32. if(strlen($errorFlag)>0){
  33.     imagestring($img, 3, 2, 2,  $errorFlag, $text_colour);
  34. }else{
  35.     $Y = 2;
  36.     $fh = fopen($file, 'r');
  37.     while($line = fgets($fh)){
  38.         $line = str_replace("\r\n", "", $line);
  39.         imagestring($img, 4, 2, $Y, $line, $text_colour);
  40.         $Y = $Y + $lineheight;
  41.     }
  42.     fclose($fh);
  43. }
  44. header("Content-type: image/png");
  45. imagepng($img);
  46. imagedestroy($img);
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment