I'm writing a script that does image manipulation, and trying to take some of the images I use in an imagecopy() out of the filesystem as images, and put them directly in the php file as strings assigned to variables. Of course, they're binary so they garbledygook everything if they're not converted, so I want to convert them with base64_encode. To test this I have a test script that makes me think that this may be impossible, and that there may be a weird bug somewhere in this php version. Weird thing is, the string works ok if it's read with fread or imagecreatefrompng, and then directly output with imagepng. However, if this data is encoded with base64_encode as $x1, and $x1 is then decoded as $x2 with base64_decode, imagecreatefrompng($x2) hangs (php produces no output it seems, none either from code prior to imagecreatefrompng() ), even if the script determines that all these values are identical (with the === operator and strcmp() ) on scriptruns when the critical line imagecreatefrompng($whatever) is commented out.

Sample: (run on 4.3.4)

 if (is_file($filename)) {
  $fd = @fopen($filename,"r");
  $image_string = fread($fd,filesize($filename));
  $image2 = base64_encode($image_string);
  $image3 = base64_decode($image2);
//  echo strcmp($image_string, $image3);             commented line 0
  if($image_string <> $image3) die('not equal');
//  if($image_string === $image3) die('same type');  commented line 1
  if(!$image3) die('none');
//  echo 'got here';                                  2
  $im = imagecreatefromstring($image3);
//$im = imagecreatefromstring($image_string);         3
//  echo 'and here';                                  4
  imagePNG($im, 'thisimage.png');
//  echo 'and here';                                  5
  header('Content-type: image/png');
  imagePNG($im);
  imagedestroy($im);
  fclose($fd);
}

when commented line 0 is uncommented, the script outputs 0, output for strcmp in cases of equality. and 1 makes the script die('same type'). When commented line 3 is uncommented and the line before it commented out, the script works fine. When the commented echo lines are uncommented (when the script uses imagecreatefromstring($image3)), php seems to produce no output.

I'd greatly appreciate any advise on getting the image source into the php file itself, and on why this is behaving so oddly. Also: is this likely to be more load-intensive than just reading in the image files with imagecreatefrompng or fopen?

Thanks,
James Coder

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



Reply via email to