JPEG Creation on the fly

Permalink
I'm trying to figure out the best way to create a jpeg on the fly.

here's the code that works, but I cannot get it to work when I add it into the C5 structure any help would be greatly appreciated. I'm really trying to pull some attributes from a page and add the text instead of the random number.

Should this code by in a controller or a helper?

$img_number = imagecreate(100,50); 
      $white = imagecolorallocate($img_number,255,255,255); 
      $black = imagecolorallocate($img_number,0,0,0); 
      $grey_shade = imagecolorallocate($img_number,204,204,204); 
      imagefill($img_number,0,0,$grey_shade); 
      ImageRectangle($img_number,5,5,94,44,$black); 
      ImageRectangle($img_number,0,0,99,49,$black); 
      $number = get_random(); 
      Imagestring($img_number,9,30,15,$number,$black); 
      header("Content-type: image/jpeg"); 
      imagejpeg($img_number);
   }
   function get_random() { 
      srand(time()); 
      $max = getrandmax();


I then reference this code from a single page like so:

<img src="http://www.grandtheatre.com/helpers/myimage.php" />

thanks
John

johndorsay