Choose a file to view:
index.php  word.php  functions.php


<?PHP
/* word.php generates a PNG image of a periodic table word from $_GET['word'].
 * It has these options:
 *  - showmass=true:  shows the molar mass of each element
 *  - shownum=true:   shows the number of each element
 *  - showname=true:  shows the name of each element
 */
 
require 'functions.php';

$word $_GET["word"];
$showname $_GET["showname"];
$shownum $_GET["shownum"];
$showmass $_GET["showmass"];

$e elements();
$words explode" "$word );
$number 1;
foreach( 
$words as $word ) {
  
$result periodic$word$e$_GET['size'] );
  for( 
$i 0$i strlen$result ); $i++ ) {
    if( 
substr$result$i) <= 'Z' && substr$result$i+1) > 'Z' ) {   // 2 character element
      
$current substr$result$i);
      
$i++;
    } else if( 
substr$result$i) <= 'Z' ) {    // 1 character element
      
$current substr$result$i);
    }
    
$symbols[$number] = addslashes($current);
    
$row mysql_query"SELECT * FROM periodic WHERE symbol='$current';" );
    
$element mysql_fetch_array$row );
    
$names[$number] = $element['name'];
    
$masses[$number] = $element['mass'];
    
$numbers[$number] = $element['number'];
    
mysql_free_result$row );
    
$number++;
  }
  
$number++;
}
mysql_close();
$number--;

$BOX_WIDTH 70;
$BOX_HEIGHT 80;
$SYMBOL_SIZE 25;
$NAME_SIZE 8;
$NUM_SIZE 10;
$MASS_SIZE 9;

$sheight 50;
$numheight 15;
$nameheight 15;
$massheight 75;
if(
$shownum == "checked" || $showname == "checked")
  
$sheight $sheight 5;
if(
$showname == "checked" && $shownum == "checked") {
  
$sheight $sheight 5;
  
$numheight 30;
}


$img=ImageCreate(($number 1) * $BOX_WIDTH ,$BOX_HEIGHT);

$white imagecolorallocate($img255255255);
$black imagecolorallocate($img000);

$font "/var/www/bgreco.net/periodic/arial.ttf";
//$symbolfont = "arialbd.ttf";
//$font = "arial.ttf";
$symbolfont "/var/www/bgreco.net/periodic/arialbd.ttf";

imageline($img00, ($number 1) * $BOX_WIDTH 10$black );
imageline($img0$BOX_HEIGHT 1, ($number 1) * $BOX_WIDTH 1$BOX_HEIGHT 1$black );

for( 
$i 0$i $number$i++ ) {
  
imageline($img$BOX_WIDTH $i0$BOX_WIDTH $i$BOX_HEIGHT$black );
  
$box imagettfbbox $SYMBOL_SIZE0$symbolfont$symbols[$i 1] );
  
imagettftext$img$SYMBOL_SIZE0$BOX_WIDTH $i - (($box[4] - $box[6])/2) + $BOX_WIDTH/1$sheight$black$symbolfont$symbols[$i 1] );
  if(
$showname == "checked") {
    
$box imagettfbbox $NAME_SIZE0$font$names[$i 1] );
    
imagettftext$img$NAME_SIZE0$BOX_WIDTH $i - (($box[4] - $box[6])/2) + $BOX_WIDTH/1$nameheight$black$font$names[$i 1] );
  }
  if(
$shownum == "checked") {
    
$box imagettfbbox $NUM_SIZE0$symbolfont$numbers[$i 1] );
    
imagettftext$img$NUM_SIZE0$BOX_WIDTH $i - (($box[4] - $box[6])/2) + $BOX_WIDTH/1$numheight$black$symbolfont$numbers[$i 1] );
  }
  if(
$showmass == "checked") {
    
$box imagettfbbox $MASS_SIZE0$font$masses[$i 1] );
    
imagettftext$img$MASS_SIZE0$BOX_WIDTH $i - (($box[4] - $box[6])/2) + $BOX_WIDTH/1$massheight$black$font$masses[$i 1] );
  }
}

Header('Content-type:image/png');
ImagePNG($img);
ImageDestroy($img);
?>