Ejemplo n.º 1
0
 /**
  * Get an image.
  *
  * Returns an image resource or false on failure. Fetches the image from
  * CCP if needed.
  * @param integer $id
  * @param integer $size
  * @return resource Image resource or false on failure.
  */
 static function get($id, $size = 64)
 {
     $id = (int) $id;
     $size = (int) $size;
     if ($size != 32 && $size != 64) {
         return false;
     }
     if (!$id) {
         return imagecreatefromjpeg("img/portrait_0_{$size}.jpg");
     }
     // If it's in the cache then read it from there.
     if (CacheHandler::exists("{$id}_{$size}.png", "img")) {
         return imagecreatefrompng(CacheHandler::getInternal("{$id}_{$size}.png", "img"));
     } else {
         $img = self::fetchImage($id, $size);
         imagepng($img, CacheHandler::getInternal("{$id}_{$size}.png", "img"));
         return $img ? $img : imagecreatefromjpeg("img/portrait_0_{$size}.jpg");
     }
 }
Ejemplo n.º 2
0
 /**
  * Return the file path for the pilot's portrait.
  *
  * The portrait is not generated by this function. If the portrait does
  * not exist then the path it would use is returned.
  * @param integer $size The desired portrait size.
  * @param integer $id The pilot ID to use. If not given and this is instantiated
  * use the ID for this pilot.
  * @return string path for a portrait.
  */
 public function getPortraitPath($size = 64, $id = 0)
 {
     $size = intval($size);
     $id = intval($id);
     if (!$id) {
         $id = $this->getExternalID();
     }
     return CacheHandler::getInternal($id . "_" . $size . ".jpg", "img");
 }
Ejemplo n.º 3
0
        } else {
            header('Content-Type: image/jpeg');
            readfile(CacheHandler::get("{$plt_ext_id}_sig_{$id}.jpg", 'img'));
            die;
        }
    }
}
$pid = $pilot->getExternalID();
$cachePath = $pilot->getPortraitPath(256);
$thumb = new thumb($pid, 256);
if (!$thumb->isCached()) {
    $thumb->genCache();
}
// check template
if (!is_dir(dirname(__FILE__) . '/signatures/' . $sig_name)) {
    errorPic('Template not found.');
}
// let the template do the work, we just output $im
require dirname(__FILE__) . '/signatures/' . $sig_name . '/' . $sig_name . '.php';
if (headers_sent()) {
    trigger_error('An error occured. Headers have already been sent.<br/>', E_USER_ERROR);
}
if (ob_get_contents()) {
    trigger_error('An error occured. Content has already been sent.<br/>', E_USER_ERROR);
} else {
    header('Content-Type: image/jpeg');
    imagejpeg($im, CacheHandler::getInternal("{$plt_ext_id}_sig_{$id}.jpg", 'img'), 90);
    readfile(CacheHandler::getInternal("{$plt_ext_id}_sig_{$id}.jpg", 'img'));
}
ob_end_flush();
die;
Ejemplo n.º 4
0
function goType($type, $id, $size = 64, $imghost = "")
{
    if ($size != 32 && $size != 64 && $size != 24 && $size != 48 && !($type == "ship" && ($size == 256 || ($size = 512)))) {
        show404();
    }
    if ($id == 0) {
        if ($size == 32 || $size == 64 || $size == 128 || $size == 256) {
            header("Location: {$imghost}img/portrait_0_{$size}.jpg");
        } else {
            header("Location: {$imghost}img/portrait_0_64.jpg");
        }
        die;
    }
    define('KB_CACHEDIR', 'cache');
    require_once "common/includes/class.cachehandler.php";
    // If it's in the cache then read it from there.
    if (CacheHandler::exists("{$id}_{$size}.png", "img")) {
        expiryHeaders("png", CacheHandler::getInternal("{$id}_{$size}.png", "img"));
        readfile(CacheHandler::getInternal("{$id}_{$size}.png", "img"));
        die;
    }
    //TODO: add an optional memcache backed by the filecache
    //Ships are available at 256 and 512
    if ($type == 'ship' && $size > 64) {
        $img = fetchImage($id, "Render", $size, "png");
    } else {
        if ($size > 32) {
            if (CacheHandler::exists("{$id}_64.png", "img")) {
                $img = imagecreatefrompng(CacheHandler::getInternal("{$id}_64.png", "img"));
            } else {
                $img = fetchImage($id, "InventoryType", 64, "png");
            }
            if ($img && $size != 64) {
                resize($size, 64, $img, CacheHandler::getInternal("{$id}_{$size}.png", "img"));
            }
        } else {
            if (CacheHandler::exists("{$id}_32.png", "img")) {
                $img = imagecreatefrompng(CacheHandler::getInternal("{$id}_32.png", "img"));
            } else {
                $img = fetchImage($id, "InventoryType", 32, "png");
            }
            if ($img && $size != 32) {
                resize($size, 32, $img, CacheHandler::getInternal("{$id}_{$size}.png", "img"));
            }
        }
    }
    if (!$img) {
        show404();
    }
    expiryHeaders("png", CacheHandler::getInternal("{$id}_{$size}.png", "img"));
    readfile(CacheHandler::getInternal("{$id}_{$size}.png", "img"));
    die;
}
Ejemplo n.º 5
0
 function genNPC()
 {
     $source = 'img/corps/' . $this->id . '.png';
     if (!file_exists($source)) {
         $this->id = 0;
         $source = 'img/corps/0.png';
         $this->thumb = CacheHandler::getInternal($this->id . '_' . $this->size . '.png', $this->thumbDir);
     }
     $img = imagecreatefrompng($source);
     if ($img) {
         $newimg = imagecreatetruecolor($this->size, $this->size);
         $color = imagecolortransparent($newimg, imagecolorallocatealpha($newimg, 0, 0, 0, 127));
         imagefill($newimg, 0, 0, $color);
         imagesavealpha($newimg, true);
         $oldx = imagesx($img);
         $oldy = imagesy($img);
         imagecopyresampled($newimg, $img, 0, 0, 0, 0, $this->size, $this->size, $oldx, $oldy);
         // Check the cache directories have been created.
         CacheHandler::getInternal($this->id . '_' . $this->size . '.png', $this->thumbDir);
         return imagepng($newimg, $this->thumb);
     }
     return false;
 }