Bug #1470: ImageGif outputs bad image
| From: | xuyifeng at telekbird dot com dot cn | Date: | Sun, 30 May 1999 07:55:49 +0000 |
| Subject: | Bug #1470: ImageGif outputs bad image | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-6294@lists.php.net to get a copy of this message | ||
From: xuyifeng@telekbird.com.cn
Operating system: WindowsNT
PHP version: 3.0.6
PHP Bug Type: Other
Bug description: ImageGif outputs bad image
I am current using PHP3.06 for Win32, I have found that the PHP author made a same mistaken with me,
PHP uses standard C runtime library function fwrite (or write ?) to output binary data, this will
produce
unexpected result, because under Microsoft Windows/NT, standard output is always opened as text
mode,
this means that if you output char '\n', it will be outputed as '\r\n', 0x0a
will be output as 0x0d0a, so if
your image contains char 0x0a, when you output image data, it will outputs 0x0d0a, and the image
stream
is damaged.
to avoid this problem, there is two methods:
1)
PHP should call _setmode functions when it startups,
result = _setmode( _fileno( stdout ), _O_BINARY);
this also resolves another problem:
PHP program want to send binary data to user client, but binary stream is changed unexpected.
2)
use Win32 API WriteFile, this function needs a Win32 file handle,
to get Win32 file handle, you should use _fileno and _get_osfhandle, the later function is
in io.h.
I recommand use first method.
I know Microsoft Windows sucks, but it exists there, we need deal with it.
sorry for my poor english, because I am in China, it isn't my native language.
I wish PHP make better and better.
XuYifeng
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net