Author Topic: Imagecreate help needed  (Read 877 times)

Offline Widell

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
    • OTWG - Online Turnbased Wargame
Imagecreate help needed
« on: January 19, 2007, 10:50:41 AM »
In my OTWG project I need to create an image (PNG, JPEG whatever) from two or more other images and present the resulting image to the user.

First the file being linked to from the main menu of OTWG. Has the following code to call the image
Code: [Select]
$image_gen = '<img src= "map_generate.php">';I then send the $image_gen as part of the HTML string etc

The map_generate.php contain more or less the following:
 
Code: [Select]
header("Content-type: image/png");
$map = imagecreatefrompng('../../resources/images/map.png');
imagepng($map);
imagedestroy($map);

This does not seem to work. What am I missing here? Any help is greatly appreciated
Widell
Online Turnbased Wargame, current release 0.1.3 - http://otwg_hq.kodapa.com

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Imagecreate help needed
« Reply #1 on: January 30, 2007, 03:54:55 AM »
Did you get this fixed yet?
I'm not sure what's wrong, the code looks fine to me.

Here's a snippet from the PHP documentation website for making a simple picture from a PNG:

Code: [Select]
<?php

header
("Content-type: image/png");
$string $_GET['text'];
$im    imagecreatefrompng("images/button1.png");
$orange imagecolorallocate($im22021060);
$px    = (imagesx($im) - 7.5 strlen($string)) / 2;
imagestring($im3$px9$string$orange);
imagepng($im);
imagedestroy($im);

?>

Offline Widell

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
    • OTWG - Online Turnbased Wargame
Re: Imagecreate help needed
« Reply #2 on: February 24, 2007, 02:54:58 PM »
Hi - Have been AWOL due to RL issues.... No, not fixed yet, and I truly don't understand what's wrong. Below is the complete code for the map_generate.php

Code: [Select]

header("Content-type: image/png");
$map = imagecreatefrompng('../../resources/images/scenario_1_map.png') or die("Cannot create basic map image");

$query_units = "SELECT * FROM otwg_e107_otwg_unit WHERE Side_ID = '1' AND Loc_X > '0'";
$result_units = mysql_query($query_units) or die("Query units failed");
while ($row_units = mysql_fetch_array($result_units, MYSQL_ASSOC))
{
$unit = imagecreatefrompng('../../resources/images/'.$row_units[Image_ID].'');
$insert_x = imagesx($unit);
$insert_y = imagesy($unit);
imagecopymerge($map,$unit,$row_units[Loc_X],$row_units[Loc_Y],0,0,$insert_x,$insert_y,100);
}

imagepng($map);
imagedestroy($map);
imagedestroy($unit);

mysql_free_result($result_units); */

The above doesn't work, while the hard coded version below does...

Code: [Select]

header("Content-type: image/png");
$map = imagecreatefrompng('../../resources/images/scenario_1_map.png') or die("Cannot create basic map image");

$unit = imagecreatefrompng('../../resources/images/green_infantry.png');
$insert_x = imagesx($unit);
$insert_y = imagesy($unit);
imagecopymerge($map,$unit,275,100,0,0,$insert_x,$insert_y,100);

imagepng($map);
imagedestroy($map);
imagedestroy($unit);

The map_display.php code is the same for both examples. Any feedback is appreciated
Widell
Online Turnbased Wargame, current release 0.1.3 - http://otwg_hq.kodapa.com

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Imagecreate help needed
« Reply #3 on: February 25, 2007, 05:30:12 AM »
Hmm, since you say that the hardcoded version works, I think it might be a problem with your $row_units variable.
You should try and see if the variable exists and the query is working properly.

Offline Widell

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
    • OTWG - Online Turnbased Wargame
Re: Imagecreate help needed
« Reply #4 on: February 27, 2007, 01:03:38 PM »
 :D Finally resolved it! It was a nested set of files which made the include files "useless". Once I got that in order, it started working as intended....
Widell
Online Turnbased Wargame, current release 0.1.3 - http://otwg_hq.kodapa.com

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal