public function getfromtxt($pseudo) { $raw_file = DB::get_id2desc_path(); $file_path = Client::getFile($raw_file . '.txt'); $contents = file_get_contents($file_path); if ($contents) { $pattern = '/' . $pseudo . '#(.*?)#/s'; preg_match($pattern, $contents, $match); $this->desc = $match[1]; } }
public function dupeImage() { $raw_file = DB::get_item_collection_path($this->img_file); $file_path = Client::getFile($raw_file . '.bmp'); if (file_get_contents($file_path)) { header('Content-type: image/png'); $im = imagecreatefrombmp($file_path); //$purple = imagecolorallocate($im, 255, 0, 255); //imagecolortransparent($im,$purple); imagepng($im); imagedestroy($im); } else { echo "File does not exist!"; } }
} // Decode path $path = str_replace('\\', '/', utf8_decode(urldecode($_SERVER['REQUEST_URI']))); $path = preg_replace('/\\?.*/', '', $path); // remove query $directory = basename(dirname(__FILE__)); // Check Allowed directory if (!preg_match('/\\/(' . $directory . '\\/)?(data|BGM)\\//', $path)) { Debug::write('Forbidden directory, you can just access files located in data and BGM folder.', 'error'); Debug::output(); } // Get file $path = preg_replace('/(.*(' . $directory . '\\/)?)(data|BGM\\/.*)/', '$3', $path); $path = str_replace('/', '\\', $path); $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION)); $file = Client::getFile($path); // File not found, end. if ($file === false) { Debug::write('Failed, file not found...', 'error'); Debug::output(); } else { Debug::write('Success !', 'success'); } header('Status: 200 OK', true, 200); header("Cache-Control: max-age=2592000, public"); header("Expires: Sat, 31 Jan 2015 05:00:00 GMT"); // Display appropriate header switch ($ext) { case 'jpg': case 'jpeg': header('Content-type:image/jpeg');
/** * Render an image */ protected final function renderImage(&$img, $param) { $file_spr = false; $file_act = false; // Nothing to render... if (isset($param['scale'])) { if ($param['scale'] == 0) { return; } } // Use the same path if (!empty($param['path'])) { $file_spr = Client::getFile($param['path'] . '.spr'); $file_act = Client::getFile($param['path'] . '.act'); } else { if (!empty($param['spr']) && !empty($param['act'])) { if ($param['act'] === '.act' || $param['spr'] === '.spr') { return; } $file_spr = Client::getFile($param['spr']); $file_act = Client::getFile($param['act']); // Act file not found, search for the act file near .spr ? if ($file_act === false) { $file_act = Client::getFile(current(explode('.spr', $param['spr'])) . '.act'); } } } // Don't render if there is nothing to render (file not found or not defined) if ($file_spr === false || $file_act === false) { return; } // Always render on top (except for robe on some case) $render_onTop = true; // Calculate action and animation $action = max(0, $this->action * 8) + max(0, $this->direction) % 8; // Doridori mod only with some conditions if (get_class($this) === 'CharacterHeadRender' || get_class($this) === 'CharacterRender' && !empty($param['head']) && ($this->action === CharacterRender::ACTION_IDLE || $this->action === CharacterRender::ACTION_SIT)) { $doridori = $this->doridori % 3; $anim = 0; } else { // All animations are link to the body animation // If we update it, we have to update others. if (!empty($param['body'])) { $anim =& $this->body_animation; // Durty trick with doridori on body. if (get_class($this) === 'CharacterRender' && ($this->action === CharacterRender::ACTION_IDLE || $this->action === CharacterRender::ACTION_SIT)) { $this->doridori %= 3; $anim = $this->doridori; } } else { $anim = $this->body_animation; } $doridori = -1; } // Load spr and act $spr = new Sprite($file_spr); $act = new Action($file_act); $animation = $act->getAnimation($action, $anim, $doridori); // If have palette, load it if (!empty($param['pal'])) { if ($file_pal = Client::getFile($param['pal'])) { $spr->palette = file_get_contents($file_pal); } } $pos = $animation->pos[0]; $reference = isset($param['pos']) ? $param['pos'] : $pos; // Robe can be display behind the character some times if (isset($param['robe'])) { $render_onTop = DB::robe_ontop($this->param['class'], $this->param['sex'], $param['robe'], $action, $anim); } else { if (isset($param['shield'])) { $direction = max(0, $this->direction % 8); $render_onTop = $direction !== self::DIRECTION_NORTHWEST && $direction !== self::DIRECTION_NORTHEAST && $direction !== self::DIRECTION_NORTH; } } // Robe zIndex if (!$render_onTop) { $_img = $img; $img = $this->createImage(); } // Draw all layers foreach ($animation->layers as $layer) { // Avoid rendering empty images if ($layer->index > -1) { // RGBA image is after pal image $index = $layer->index; if ($layer->spr_type === Sprite::TYPE_RGBA) { $index += $spr->rgba_index; } // Build sprite image $image = $spr->getImage($index, $layer->is_mirror, $layer->color, self::$background_color); $width = imagesx($image); $height = imagesy($image); $scale = $layer->scale; // Main scale feature if (isset($param['scale'])) { $scale[0] *= $param['scale']; $scale[1] *= $param['scale']; } // Generate scale if ($scale[0] !== 1.0 && $scale[1] !== 1.0) { // New size $w = $width * $scale[0]; $h = $height * $scale[1]; // Copy image to new layer (resize) $tmp = $this->createImage($w, $h); imagecopyresampled($tmp, $image, 0, 0, 0, 0, $w, $h, $width, $height); imagedestroy($image); $image = $tmp; $width = $w; $height = $h; } else { if (!imageistruecolor($image)) { $tmp = $this->createImage($width, $height); imagecopy($tmp, $image, 0, 0, 0, 0, $width, $height); imagedestroy($image); $image = $tmp; } } // Apply a rotation if (!empty($layer->angle)) { $image = imagerotate($image, -$layer->angle, imagecolortransparent($image), 1); $width = imagesx($image); $height = imagesy($image); } // Calculate the position $x = $this->dot_reference[0] - $width / 2 + $layer->pos[0] + $reference->x - intval($pos->x); $y = $this->dot_reference[1] - $height / 2 + $layer->pos[1] + $reference->y - intval($pos->y); // Copy image to main layer imagecopymerge($img, $image, $x, $y, 0, 0, $width, $height, $layer->color[3] * 100); imagedestroy($image); } } // Robe/shield ontop if (!$render_onTop) { imagecopy($img, $_img, 0, 0, 0, 0, $this->image_size[0], $this->image_size[1]); } // Return its pos for reference return $pos; }