On Mon, March 20, 2006 8:35 pm, je killen wrote:

>> I really don't understand, though, why you are doing things the way
>> you describe...
> I only want one image file for each distinct letter, no repeats
> because
> I can't put two or more files with the same name
> in the same dir. The images need to be drug around DHTML style and
> reassembled into the correct word. Javascript
> needs to be able to establish when the chars are in the correct order
> so I need to have php feed it a formula to refer to.

Okay, now we are getting somewhere!

The easiest way to meet the unique filename requirement is to name
each file after its letter:
a.png
b.png
c.png

Of course, they only need to APPEAR that way to the browser and
Javascript.

In reality, you may not actually have a file named "a.png" at all.

For example, if your HTML is like this:
<img src="/drawchar.php/a.png" />

And you have a PHP script drawchar.php like this:
<?php
  //EG: $path_info will be "/a.png",
  //because that is what is in tha URL AFTER the PHP script name
  $path_info = $_SERVER['PATH_INFO'];

  //get JUST the one letter
  $char = substr($path_info, 1, 1);

  //Create the image:
  $image = imagecreatetruecolor(40, 10);

  //Boring colors, but works for now:
  $white = imagecolorallocate($image, 255, 255, 255);
  $black = imagecolorallocate($image, 0, 0, 0);

  //make the background white:
  imagefilledrectangle($image, 0, 0, 39, 9, $white);

  //draw the character:
  $font = 3; //Fonts can be 1 through 5
  $x = 2;
  $y = 38;
  imagechar($image, $font, $x, $y, $char, $black);

  //Find out how big the image is:
  ob_start();
  imagepng($image);
  $image_raw = ob_get_contents();
  ob_end_clean();
  $image_length = strlen($image_raw);

  //Send suitable headers:
  header("Content-type: image/png");
  header("Content-length: $image_length");

  //Send the data:
  echo $image_raw;
?>

You can now just pass the word 'dissatisfaction' around, and use PHP
or JavaScript to output individual images.

I'll do it in PHP:

<?php
  $word = 'dissatisfaction';
  for ($i = 0, $len = strlen($word); $i < $len; $i++){
    $char = $word[$i]; //or use substr if you like
    echo "<img src=\"/drawchar.php/$char.png\" />";
  }
?>

I haven't run this code to test it, so there might be a typo, but it's
going to be MUCH easier to maintain than what you've got going...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to