Example #1
0
function scale_image($filename, $width = 100, $height = 100)
{
    $res[0] = $width;
    $res[1] = $height;
    $size = getimagesize_remote($filename);
    if ($size[0] < $res[0] && $size[1] < $res[1]) {
        if ($res[0] / $size[0] > $res[1] / $size[1]) {
            $width = $size[0] * ($res[1] / $size[1]);
            $height = $res[1];
        } else {
            $width = $res[0];
            $height = $size[1] * ($res[0] / $size[0]);
        }
    } elseif ($size[0] < $res[0]) {
        $width = $size[0] * ($res[1] / $size[1]);
        $height = $res[1];
    } else {
        $width = $res[0];
        $height = $size[1] * ($res[0] / $size[0]);
    }
    $end_size[0] = $width;
    $end_size[1] = $height;
    return $end_size;
}
 function resize()
 {
     global $mtconf;
     $imagetype = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG', 4 => 'SWF', 5 => 'PSD', 6 => 'BMP', 7 => 'TIFF', 8 => 'TIFF', 9 => 'JPC', 10 => 'JP2', 11 => 'JPX', 12 => 'JB2', 13 => 'SWC', 14 => 'IFF');
     if (substr(0, 7, $this->tmpFile) == 'http://') {
         $imginfo = getimagesize_remote($this->tmpFile);
     } else {
         $imginfo = getimagesize($this->tmpFile);
     }
     $imginfo[2] = $imagetype[$imginfo[2]];
     # GD can only handle GIF, JPG & PNG images
     if ($imginfo[2] != 'JPG' && $imginfo[2] != 'PNG' && $imginfo[2] != 'GIF' && ($this->method == 'gd1' || $this->method == 'gd2')) {
         die("ERROR: GD can only handle JPG, GIF and PNG files!");
     }
     # height/width
     $srcWidth = $imginfo[0];
     $srcHeight = $imginfo[1];
     # Generate new width/height
     $ratio = max($srcWidth, $srcHeight) / $this->size;
     $ratio = max($ratio, 1.0);
     $destWidth = (int) ($srcWidth / $ratio);
     $destHeight = (int) ($srcHeight / $ratio);
     $offWidth = 0;
     $offHeight = 0;
     if ($this->square && $srcWidth > $this->size && $srcHeight > $this->size) {
         if ($srcWidth > $srcHeight) {
             $offWidth = ($srcWidth - $srcHeight) / 2;
             $offHeight = 0;
             $srcWidth = $srcHeight;
             $destHeight = $destWidth;
         } elseif ($srcHeight > $srcWidth) {
             $offWidth = 0;
             $offHeight = ($srcHeight - $srcWidth) / 2;
             $srcHeight = $srcWidth;
             $destWidth = $destHeight;
         }
     }
     # Method for thumbnails creation
     switch ($this->method) {
         case "gd1":
             if (!function_exists('imagecreatefromjpeg')) {
                 die('GD image library not installed!');
             }
             if ($imginfo[2] == 'JPG') {
                 $src_img = imagecreatefromjpeg($this->tmpFile);
             } else {
                 $src_img = imagecreatefrompng($this->tmpFile);
             }
             if (!$src_img) {
                 $ERROR = $lang_errors['invalid_image'];
                 return false;
             }
             $dst_img = imagecreate($destWidth, $destHeight);
             imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
             ob_start();
             imagejpeg($dst_img, null, $this->quality);
             $this->imageData = ob_get_contents();
             ob_end_clean();
             imagedestroy($src_img);
             imagedestroy($dst_img);
             break;
         case "gd2":
             if (!function_exists('imagecreatefromjpeg')) {
                 die('GD image library not installed!');
             }
             if (!function_exists('imagecreatetruecolor')) {
                 die('GD2 image library does not support truecolor thumbnailing!');
             }
             switch ($imginfo[2]) {
                 case 'JPG':
                     $src_img = imagecreatefromjpeg($this->tmpFile);
                     $dst_img = imagecreatetruecolor($destWidth, $destHeight);
                     break;
                 case 'PNG':
                     $src_img = imagecreatefrompng($this->tmpFile);
                     $dst_img = $this->imagecreatetruecolortransparent($destWidth, $destHeight);
                     break;
                 case 'GIF':
                     $src_img = imagecreatefromgif($this->tmpFile);
                     $dst_img = imagecreatetruecolor($destWidth, $destHeight);
                     $colorTransparent = imagecolortransparent($src_img);
                     imagepalettecopy($src_img, $dst_img);
                     imagefill($dst_img, 0, 0, $colorTransparent);
                     imagecolortransparent($dst_img, $colorTransparent);
                     imagetruecolortopalette($dst_img, true, 256);
                     break;
             }
             imagecopyresampled($dst_img, $src_img, 0, 0, $offWidth, $offHeight, $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
             ob_start();
             switch ($imginfo[2]) {
                 case 'GIF':
                     imagegif($dst_img);
                     break;
                 case 'PNG':
                     imagepng($dst_img);
                     break;
                 case 'JPG':
                 default:
                     imagejpeg($dst_img, null, $this->quality);
                     break;
             }
             $this->imageData = ob_get_contents();
             ob_end_clean();
             imagedestroy($src_img);
             imagedestroy($dst_img);
             break;
         case "netpbm":
             if ($mtconf->get('img_netpbmpath')) {
                 if (!is_dir($mtconf->get('img_netpbmpath'))) {
                     echo "NetPbm path incorrect";
                     die;
                 }
             }
             if ($imginfo[2] == 'PNG') {
                 $cmd = $mtconf->get('img_netpbmpath') . "pngtopnm {$this->tmpFile} | " . $mtconf->get('img_netpbmpath') . "pnmscale -xysize {$destWidth} " . (int) $destHeight . " | " . $mtconf->get('img_netpbmpath') . "pnmtopng > " . JPATH_ROOT . DS . 'media' . DS . $this->imageName;
             } else {
                 if ($imginfo[2] == 'JPG') {
                     $cmd = $mtconf->get('img_netpbmpath') . "jpegtopnm {$this->tmpFile} | " . $mtconf->get('img_netpbmpath') . "pnmscale -xysize {$destWidth} " . (int) $destHeight . " | " . $mtconf->get('img_netpbmpath') . "pnmtojpeg -quality={$this->quality} > " . JPATH_ROOT . DS . 'media' . DS . $this->imageName;
                 } else {
                     if ($imginfo[2] == 'GIF') {
                         $cmd = $mtconf->get('img_netpbmpath') . "giftopnm {$this->tmpFile} | " . $mtconf->get('img_netpbmpath') . "pnmscale -xysize {$destWidth} " . (int) $destHeight . " | " . $mtconf->get('img_netpbmpath') . "ppmquant 256 | " . $mtconf->get('img_netpbmpath') . "ppmtogif > " . JPATH_ROOT . DS . 'media' . DS . $this->imageName;
                     }
                 }
             }
             exec($cmd);
             break;
         case "imagemagick":
             $tmp_name = substr(strrchr($this->directory . $this->imageName, "/"), 1);
             copy($this->tmpFile, JPATH_ROOT . DS . 'media' . DS . $tmp_name);
             $uploadfile = JPATH_ROOT . DS . 'media' . DS . $tmp_name;
             $cmd = $mtconf->get('img_impath') . "convert -resize " . $destWidth . "x" . (int) $destHeight . " {$uploadfile} " . JPATH_ROOT . DS . 'media' . DS . $this->imageName;
             exec($cmd);
             unlink($uploadfile);
             break;
     }
     if ($this->method == 'netpbm' || $this->method == 'imagemagick') {
         $filename = JPATH_ROOT . DS . 'media' . DS . $this->imageName;
         $handle = fopen($filename, "r");
         $this->imageData = fread($handle, filesize($filename));
         fclose($handle);
         unlink(JPATH_ROOT . DS . 'media' . DS . $this->imageName);
     }
     # Set mode of uploaded picture
     if (file_exists($this->directory . $this->imageName)) {
         chmod($this->directory . $this->imageName, octdec('755'));
         # We check that the image is valid
         $imginfo = getimagesize($this->directory . $this->imageName);
         if ($imginfo == null) {
             return false;
         } else {
             return true;
         }
     } else {
         return false;
     }
 }
Example #3
0
function Show_Settlers()
{
    global $db;
    global $game;
    global $config;
    // Men BASIC
    Show_Main();
    if (($user = $db->queryrow('SELECT * FROM user WHERE user_id="' . INDEPENDENT_USERID . '" LIMIT 1')) === false) {
        $game->out('<span class="sub_caption">' . constant($game->sprache("TEXT33")) . ' (id=' . $_REQUEST['id'] . '<br>' . constant($game->sprache("TEXT34")) . '</span>');
    } else {
        $game->out('
<table border=0 cellpadding=2 cellspacing=2 wisth="450" class="style_outer" align="center">
  <tr>
    <td>
      <center><span class="caption">' . $user['user_name'] . '</span></center>
    </td>
  </tr>
  <tr>
    <td>
      <table border=0 cellpadding=1 cellspacing=1 width=450 class ="style_inner">
        <tr>');
        //avatar:
        if (!empty($user['user_avatar'])) {
            $info = getimagesize_remote($user['user_avatar']);
            if ($info[0] > 0 && $info[1] > 0 && $info[0] <= 150 && $info[1] <= 250) {
                $game->out('<td width=' . $info[0] . '><img src="' . $user['user_avatar'] . '"></td><td width=25></td><td width=425-' . $info[0] . ' valign=top>');
            } else {
                if ($info[0] > 0 && $info[1] > 0) {
                    $width = 150;
                    $height = 150;
                    if ($info[0] > $info[1]) {
                        $height = 150 * ($info[1] / $info[0]);
                    } else {
                        $width = 150 * ($info[0] / $info[1]);
                    }
                    $game->out('<td width=' . $width . '><img src="' . $user['user_avatar'] . '" width="' . $width . '" height="' . $height . '"></td><td width=25></td><td width=425-' . $width . ' valign=top>');
                } else {
                    $game->out('<td width=200></td><td width=250 valign=top>');
                }
            }
        } else {
            $game->out('<td width=200></td><td width=250 valign=top>');
        }
        $rasse = $RACE_DATA[$user['user_race']][0];
        $planets = $db->queryrow('SELECT count(planet_id) AS num FROM planets WHERE planet_owner="' . $user['user_id'] . '"');
        $game->out('
            <table border=0 cellpadding=2 cellspacing=2 class="style_inner">
              <tr>
                <td width=70><span class="text_large">' . constant($game->sprache("TEXT19")) . '</b></span></td>
                <td width=150><span class="text_large">' . $planets['num'] . '</td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<br>
');
        $_link_image = '<a href="usermap.php?user='******'user_name'] . '&size=6&map" target=_blank><img src="usermap.php?user='******'user_name'] . '&size=1" border=0></a>';
        $game->out('
<br>

<table border=0 cellpadding=2 cellspacing=2 width="450" class="style_outer">
  <tr>
    <td><span class="sub_caption">' . constant($game->sprache("TEXT52")) . '</span></td>
  </tr>
  <tr>
    <td>
      <table border=0 cellpadding=2 cellspacing=2 width="450" class="style_inner">
        <tr>
          <td align="center">' . $_link_image . '</td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<br>
');
        $game->out('
<table border=0 cellpadding=2 cellspacing=2 width="450" class="style_outer">
  <tr>
    <td><span class="sub_caption">' . constant($game->sprache("TEXT53")) . '</span></td>
  </tr>');
        $game->out('
  <tr>
    <td align="center">
      <b>' . constant($game->sprache("TEXT99")) . '</b>
    </td>
  </tr>
  <tr>
    <td>
      <table border=0 cellpadding=2 cellspacing=2 width="450" class="style_inner">
        <tr>
          <td width=80><b>' . constant($game->sprache("TEXT69")) . '</td>
          <td width=200><b>' . constant($game->sprache("TEXT18")) . '</td>
          <td width=60><b>' . constant($game->sprache("TEXT102")) . '</td>
          <td width=50><b>' . constant($game->sprache("TEXT55")) . '</td>
        </tr>
');
        $sql_pl = 'SELECT pl.planet_id, pl.planet_name, pl.best_mood, pl.best_mood_user, pl.sector_id, pl.planet_distance_id, pl.planet_type, sys.system_x, sys.system_y
                   FROM (planets pl)
                   INNER JOIN (starsystems sys) USING (system_id)
                   INNER JOIN (starsystems_details sd) ON pl.system_id = sd.system_id AND sd.user_id = ' . $game->player['user_id'] . '
                   WHERE pl.planet_owner = "' . INDEPENDENT_USERID . '" AND
                         pl.planet_type IN ("a","b","c","d","m","o","p") 
                   GROUP BY pl.planet_id
                   ORDER BY pl.sector_id, pl.system_id, pl.planet_name';
        $planetquery = $db->query($sql_pl);
        $numero_righe = $db->num_rows($planetquery);
        if ($numero_righe == 0) {
            $game->out('<tr><td> --- </td><td> --- </td><td> --- </td><td> --- </td></tr>');
        } else {
            $sett_diplo = $db->fetchrowset($planetquery);
            foreach ($sett_diplo as $planet) {
                $game->out('<tr><td>' . $game->get_sector_name($planet['sector_id']) . ':' . $game->get_system_cname($planet['system_x'], $planet['system_y']) . ':' . ($planet['planet_distance_id'] + 1) . '</td><td><a href="' . parse_link('a=tactical_cartography&planet_id=' . encode_planet_id($planet['planet_id'])) . '">');
                if ($planet['planet_name'] == "") {
                    $planet['planet_name'] = "(<i>" . constant($game->sprache("TEXT40")) . "</i>)";
                }
                $game->out($planet['planet_name'] . '</a></td>');
                // Insane number of SELECT
                $sql = 'SELECT SUM(mood_modifier) as mood FROM settlers_relations WHERE planet_id = ' . $planet['planet_id'] . ' AND user_id = ' . $game->player['user_id'];
                $u_m = $db->queryrow($sql);
                if (isset($u_m['mood']) && !empty($u_m['mood'])) {
                    $user_mood = $u_m['mood'];
                    $game->out('<td><span style="color: ' . ($game->player['user_id'] == $planet['best_mood_user'] || $user_mood > $planet['best_mood'] ? 'green' : 'red') . '">' . $user_mood . '</span></td>');
                } else {
                    $game->out('<td>---</td>');
                }
                $game->out('<td>' . strtoupper($planet['planet_type']) . '</td></tr>');
            }
        }
        $game->out('
      </table>
    </td>
  </tr>
  <tr>
    <td align="center">
      <b>' . constant($game->sprache("TEXT100")) . '</b>
    </td>
  </tr>
  <tr>
    <td>
      <table border=0 cellpadding=2 cellspacing=2 width="450" class="style_inner">
        <tr>
          <td width=80><b>' . constant($game->sprache("TEXT69")) . '</td>
          <td width=200><b>' . constant($game->sprache("TEXT18")) . '</td>
          <td width=60><b>' . constant($game->sprache("TEXT102")) . '</td>
          <td width=50><b>' . constant($game->sprache("TEXT55")) . '</td>
        </tr>');
        $sql_pl = 'SELECT pl.planet_id, pl.planet_name, pl.best_mood, pl.best_mood_user, pl.sector_id, pl.planet_distance_id, pl.planet_type, sys.system_x, sys.system_y
                   FROM (planets pl)
                   INNER JOIN (starsystems sys) USING (system_id)
                   INNER JOIN (starsystems_details sd) ON pl.system_id = sd.system_id AND sd.user_id = ' . $game->player['user_id'] . '
                   WHERE pl.planet_owner = "' . INDEPENDENT_USERID . '" AND
                         pl.planet_type IN ("h","n","k","l","e","f","g") 
                   GROUP BY pl.planet_id
                   ORDER BY pl.sector_id, pl.system_id, pl.planet_name';
        $planetquery = $db->query($sql_pl);
        $numero_righe = $db->num_rows($planetquery);
        if ($numero_righe == 0) {
            $game->out('<tr><td> --- </td><td> --- </td><td> --- </td><td> --- </td></tr>');
        } else {
            $sett_diplo = $db->fetchrowset($planetquery);
            foreach ($sett_diplo as $planet) {
                $game->out('<tr><td>' . $game->get_sector_name($planet['sector_id']) . ':' . $game->get_system_cname($planet['system_x'], $planet['system_y']) . ':' . ($planet['planet_distance_id'] + 1) . '</td><td><a href="' . parse_link('a=tactical_cartography&planet_id=' . encode_planet_id($planet['planet_id'])) . '">');
                if ($planet['planet_name'] == "") {
                    $planet['planet_name'] = "(<i>" . constant($game->sprache("TEXT40")) . "</i>)";
                }
                $game->out($planet['planet_name'] . '</a></td>');
                // Insane number of SELECT
                $sql = 'SELECT SUM(mood_modifier) as mood FROM settlers_relations WHERE planet_id = ' . $planet['planet_id'] . ' AND user_id = ' . $game->player['user_id'];
                $u_m = $db->queryrow($sql);
                if (isset($u_m['mood']) && !empty($u_m['mood'])) {
                    $user_mood = $u_m['mood'];
                    $game->out('<td><span style="color: ' . ($game->player['user_id'] == $planet['best_mood_user'] || $user_mood > $planet['best_mood'] ? 'green' : 'red') . '">' . $user_mood . '</span></td>');
                } else {
                    $game->out('<td>---</td>');
                }
                $game->out('<td>' . strtoupper($planet['planet_type']) . '</td></tr>');
            }
        }
        $game->out('
      </table>
    </td>
  </tr>
  <tr>
    <td align="center">
      <b>' . constant($game->sprache("TEXT101")) . '</b>
    </td>
  </tr>
  <tr>
    <td>
      <table border=0 cellpadding=2 cellspacing=2 width="450" class="style_inner">
        <tr>
          <td width=80><b>' . constant($game->sprache("TEXT69")) . '</td>
          <td width=200><b>' . constant($game->sprache("TEXT18")) . '</td>
          <td width=50><b>' . constant($game->sprache("TEXT102")) . '</td>
          <td width=50><b>' . constant($game->sprache("TEXT55")) . '</td>
        </tr>');
        $sql_pl = 'SELECT pl.planet_id, pl.planet_name, pl.best_mood, pl.best_mood_user, pl.sector_id, pl.planet_distance_id, pl.planet_type, sys.system_x, sys.system_y
                   FROM (planets pl)
                   INNER JOIN (starsystems sys) USING (system_id)
                   INNER JOIN (starsystems_details sd) ON pl.system_id = sd.system_id AND sd.user_id = ' . $game->player['user_id'] . '
                   WHERE pl.planet_owner = "' . INDEPENDENT_USERID . '" AND
                         pl.planet_type IN ("i","j","s","t","x","y") 
                   GROUP BY pl.planet_id
                   ORDER BY pl.sector_id, pl.system_id, pl.planet_name';
        $planetquery = $db->query($sql_pl);
        $numero_righe = $db->num_rows($planetquery);
        if ($numero_righe == 0) {
            $game->out('<tr><td> --- </td><td> --- </td><td> --- </td><td> --- </td></tr>');
        } else {
            $sett_diplo = $db->fetchrowset($planetquery);
            foreach ($sett_diplo as $planet) {
                $game->out('<tr><td>' . $game->get_sector_name($planet['sector_id']) . ':' . $game->get_system_cname($planet['system_x'], $planet['system_y']) . ':' . ($planet['planet_distance_id'] + 1) . '</td><td><a href="' . parse_link('a=tactical_cartography&planet_id=' . encode_planet_id($planet['planet_id'])) . '">');
                if ($planet['planet_name'] == "") {
                    $planet['planet_name'] = "(<i>" . constant($game->sprache("TEXT40")) . "</i>)";
                }
                $game->out($planet['planet_name'] . '</a></td>');
                // Insane number of SELECT
                $sql = 'SELECT SUM(mood_modifier) as mood FROM settlers_relations WHERE planet_id = ' . $planet['planet_id'] . ' AND user_id = ' . $game->player['user_id'];
                $u_m = $db->queryrow($sql);
                if (isset($u_m['mood']) && !empty($u_m['mood'])) {
                    $user_mood = $u_m['mood'];
                    $game->out('<td><span style="color: ' . ($game->player['user_id'] == $planet['best_mood_user'] || $user_mood > $planet['best_mood'] ? 'green' : 'red') . '">' . $user_mood . '</span></td>');
                } else {
                    $game->out('<td>---</td>');
                }
                $game->out('<td>' . strtoupper($planet['planet_type']) . '</td></tr>');
            }
        }
        $game->out('
      </table>
    </td>
  </tr>
</table>');
    }
}