Map image generator script
Map image generator script
I'm working on a little project to allow map developers to upload a map file to a web server, and I'm looking for a way to create an image of the radar view. I could easily have them transfer the image themself, but is there any script that can do it automatically? It could be a CGI or Perl script, but I hope there is PHP script.
-
- Registered User
- Posts: 0
- Joined: Fri Oct 28, 2005 11:59 pm
blast....err, not sure if you want to go this route.....but there is a thumbnail generator(png file) built into pybzflag......you would have to install pybzflag along with the necessary libraries.
but it does work and looks quite nice..........better than a radar view..........and you can control the size and detail shown. It reads in the present map format as well which helps a little with the flipz pyramids.
but it does work and looks quite nice..........better than a radar view..........and you can control the size and detail shown. It reads in the present map format as well which helps a little with the flipz pyramids.
.........you kids, get out of my tank...........
I suppose that could work, being that I am going to moderate each map submission for now. Maybe I'll check how BZFlag takes screen shots, and maybe modify it to only save the radar. What I'm really hoping is for a script I can run on a web server from/within a PHP script on a existing map file, and create an image with the GD libraries. Maybe I'll have to write one myself, if I get bored and have some time. I'm working on improving a local version of the stats.bzflag.org site and I want to integrate this into that site.
the thumbnailer for pybzflag is probably a better solution then. and python calls..............from what i know...........can be integrated from within a webscript much like perl.
here are coded options:
usage: worldthumbnail.py [options] worlds
options:
-h, --help show this help message and exit
-oFILE, --output=FILE Sets the file or directory name to output thumbnails to.
-sWIDTHxHEIGHT, --size=WIDTHxHEIGHT Sets the thumbnail size. Default is 160x160.
-i, --index Generates an index of world files to the directory provided with -o.
-fEXTENSION, --format=EXTENSION Sets the format, specified in the form of a file extension name, of the images to generate when an explicit filename is not given. Default is 'png'.
-aAMOUNT, --oversample=AMOUNT Sets the amount of oversampling. Higher numbers will produce smoother images with thinner borders, but will require much more memory and CPU time. Default is 3.
-tFILE, --template=FILE Sets the template file to use for producing index output. Default is 'worldindex.html' in the data directory.
-nFILE, --index-name=FILE Sets the name of the index file to produce in the output directory. Default is 'index.html'.
here are coded options:
usage: worldthumbnail.py [options] worlds
options:
-h, --help show this help message and exit
-oFILE, --output=FILE Sets the file or directory name to output thumbnails to.
-sWIDTHxHEIGHT, --size=WIDTHxHEIGHT Sets the thumbnail size. Default is 160x160.
-i, --index Generates an index of world files to the directory provided with -o.
-fEXTENSION, --format=EXTENSION Sets the format, specified in the form of a file extension name, of the images to generate when an explicit filename is not given. Default is 'png'.
-aAMOUNT, --oversample=AMOUNT Sets the amount of oversampling. Higher numbers will produce smoother images with thinner borders, but will require much more memory and CPU time. Default is 3.
-tFILE, --template=FILE Sets the template file to use for producing index output. Default is 'worldindex.html' in the data directory.
-nFILE, --index-name=FILE Sets the name of the index file to produce in the output directory. Default is 'index.html'.
- Attachments
-
- BagCity_19v4.png
- Sample
- (42.57 KiB) Downloaded 124 times
-
- farmer.png
- Sample PNG Output
- (59.16 KiB) Downloaded 116 times
.........you kids, get out of my tank...........
- Noodleroni
- Private First Class
- Posts: 154
- Joined: Mon Dec 09, 2002 7:12 pm
- Location: Bend, OR
- Contact:
There was some PHP code in jzaun's old stats.bzflag.org that makes thumbnails of BZFlag worlds, but it does look pretty sucky. If you want it, just ask me.
Also, when you get those improvements in your copy of SBO, I'd like to take a look, and hopefully integrate them into the site, if you're agreeable
Also, when you get those improvements in your copy of SBO, I'd like to take a look, and hopefully integrate them into the site, if you're agreeable

I've been working on a PHP script for this. I don't have the code done to parse the world file yet. Also, I haven't figured out the equations in order to draw objects at angles. Here's what I got so far (see it in action):Noodleroni wrote:There was some PHP code in jzaun's old stats.bzflag.org that makes thumbnails of BZFlag worlds, but it does look pretty sucky. If you want it, just ask me.
Code: Select all
<?php
function drawObject($type, $scale_x, $scale_y, $pos_x, $pos_y, $angle)
{ global $radar, $image_scale_x, $image_scale_y, $unit_scale, $color; // Load in global vars
// Calculate the point of the polygon (doesn't account for angle yet)
$x1 = ($image_scale_x / 2) - ($scale_x * $unit_scale) + ($pos_x * $unit_scale);
$y1 = ($image_scale_y / 2) - ($scale_y * $unit_scale) + ($pos_y * $unit_scale);
$x2 = ($image_scale_x / 2) + ($scale_x * $unit_scale) + ($pos_x * $unit_scale);
$y2 = ($image_scale_y / 2) - ($scale_y * $unit_scale) + ($pos_y * $unit_scale);
$x3 = ($image_scale_x / 2) + ($scale_x * $unit_scale) + ($pos_x * $unit_scale);
$y3 = ($image_scale_y / 2) + ($scale_y * $unit_scale) + ($pos_y * $unit_scale);
$x4 = ($image_scale_x / 2) - ($scale_x * $unit_scale) + ($pos_x * $unit_scale);
$y4 = ($image_scale_y / 2) + ($scale_y * $unit_scale) + ($pos_y * $unit_scale);
// Put the points into an array
$points = array(
0 => $x1,
1 => $y2,
2 => $x2,
3 => $y2,
4 => $x3,
5 => $y3,
6 => $x4,
7 => $y4,
);
switch($type) {
case "box":
$object_color = $color[box];
break;
case "pyramid":
$object_color = $color[pyramid];
break;
// Bases
case "blue":
$object_color = $color[blue];
break;
case "red":
$object_color = $color[red];
break;
case "green":
$object_color = $color[green];
break;
case "purple":
$object_color = $color[purple];
break;
default:
// Invalid object type...do nothing and return
return;
break;
}
ImageFilledPolygon($radar, $points, 4, $object_color);
}
///////////////
// Main code //
///////////////
// Add a header
header( "Content-Type: image/png" );
// Size of image
$image_scale_x = $image_scale_y = 200;
// Width of world
$world_size = 800;
// Unit scale
$unit_scale = $image_scale_x / $world_size;
// Create a blank image
$radar = ImageCreateTrueColor($image_scale_x, $image_scale_y);
// Define colors
$color[box] = ImageColorAllocate($radar, 127, 127, 127);
$color[pyramid] = ImageColorAllocate($radar, 127, 127, 255);
$color[blue] = ImageColorAllocate($radar, 0, 0, 255);
$color[red] = ImageColorAllocate($radar, 255, 0, 0);
$color[green] = ImageColorAllocate($radar, 0, 255, 0);
$color[purple] = ImageColorAllocate($radar, 255, 0, 255);
drawObject("box", 300, 300, 0, 0, 0);
drawObject("pyramid", 150, 150, 0, 0, 0);
drawObject("blue", 50, 50, 300, 300, 0);
drawObject("red", 50, 50, 300, -300, 0);
drawObject("green", 50, 50, -300, -300, 0);
drawObject("purple", 50, 50, -300, 300, 0);
ImagePNG($radar);
imagedestroy($radar);
?>
Sure thing. That was my plan in the beginning.Noodleroni wrote:Also, when you get those improvements in your copy of SBO, I'd like to take a look, and hopefully integrate them into the site, if you're agreeable

Last edited by blast on Fri Jan 23, 2004 7:12 pm, edited 2 times in total.