Map image generator script

General talk about the map making process.
Post Reply
User avatar
blast
General
General
Posts: 4746
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Map image generator script

Post by blast » Thu Jan 22, 2004 5:41 pm

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.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image

Rebel Chikorita
Registered User
Registered User
Posts: 0
Joined: Fri Oct 28, 2005 11:59 pm

Post by Rebel Chikorita » Thu Jan 22, 2004 7:56 pm

kewl :)

i'd also b nice too c mor regular jpeg pix of arial screenshots of new maps bein made wifout da need to unzip or d/l special bzf type program files...

Grumbler
Dev Monkey
Dev Monkey
Posts: 453
Joined: Wed Jul 09, 2003 3:06 pm
Location: Space

Post by Grumbler » Thu Jan 22, 2004 9:05 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.
.........you kids, get out of my tank...........

User avatar
blast
General
General
Posts: 4746
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Post by blast » Thu Jan 22, 2004 11:10 pm

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.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image

Grumbler
Dev Monkey
Dev Monkey
Posts: 453
Joined: Wed Jul 09, 2003 3:06 pm
Location: Space

Post by Grumbler » Thu Jan 22, 2004 11:35 pm

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'.
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...........

Rebel Chikorita
Registered User
Registered User
Posts: 0
Joined: Fri Oct 28, 2005 11:59 pm

Post by Rebel Chikorita » Fri Jan 23, 2004 12:21 am

kewl pix

User avatar
blast
General
General
Posts: 4746
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Post by blast » Fri Jan 23, 2004 12:24 am

Wow, that does make nice looking images. I'll have to see if I can get pybzflag working on my machine. Then again, it might be fun to play around with the GD libraries from PHP and see if I can make my own generator. ;)
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image

User avatar
Noodleroni
Private First Class
Private First Class
Posts: 154
Joined: Mon Dec 09, 2002 7:12 pm
Location: Bend, OR
Contact:

Post by Noodleroni » Fri Jan 23, 2004 4:18 am

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 :-)
Image

User avatar
blast
General
General
Posts: 4746
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Post by blast » Fri Jan 23, 2004 4:39 am

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.
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):

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);
?>
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 :-)
Sure thing. That was my plan in the beginning. ;)
Last edited by blast on Fri Jan 23, 2004 7:12 pm, edited 2 times in total.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image

User avatar
larsl
Dev Monkey
Dev Monkey
Posts: 50
Joined: Tue May 20, 2003 2:35 pm
Location: Stockholm
Contact:

Post by larsl » Fri Jan 23, 2004 12:27 pm

You need to set the Content-Type header. Konqueror just displays junk text, and when I telnet to the server and GET the script it says "Content-Type: text/html". If I save the file and open it with an image viewer it works.

User avatar
blast
General
General
Posts: 4746
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Post by blast » Fri Jan 23, 2004 3:20 pm

Okay, I've added a header to the code now. When the script is complete, I won't need that. It's just going to write the file out.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image

User avatar
blast
General
General
Posts: 4746
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Post by blast » Sun Jan 25, 2004 8:20 pm

Hmm...my web host seems to have disabled GD, so that "See it in action" link just displays a PHP error now. :lol:
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image

Grumbler
Dev Monkey
Dev Monkey
Posts: 453
Joined: Wed Jul 09, 2003 3:06 pm
Location: Space

Post by Grumbler » Fri Jul 23, 2004 2:21 pm

.........you kids, get out of my tank...........

Post Reply