Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

GD functions display images with mistake

images php coding issues or problems here.

Moderators: macek, egami, gesf

GD functions display images with mistake

Postby lisham » Mon Mar 29, 2004 2:18 am

Hi
I am using: WinXP, PHP 4.3.3
I have few problems with GD functions, like this simple code:
Code: Select all
<?
$imColor = hex2int(validHexColor($_REQUEST['color']));
$im = imagecreate(50,50);
$background = imagecolorallocate($im, $imColor['r'], $imColor['g'], $imColor['b']);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
function hex2int($hex) {
        return array( 'r' => hexdec(substr($hex, 0, 2)), // 1st pair of digits
                      'g' => hexdec(substr($hex, 2, 2)), // 2nd pair
                      'b' => hexdec(substr($hex, 4, 2))  // 3rd pair
                    );
}
function validHexColor($input = '000000', $default = '000000') {
    return (eregi('^[0-9a-f]{6}$', $input)) ? $input : $default ;
}
?>

This code on my computer return:


Warning: Cannot modify header information - headers already sent by (output started at f:\inetpub\wwwroot\php\test\gallery\image1.php:1) in f:\inetpub\wwwroot\php\test\gallery\image1.php on line 6
?PNG  IHDR22$��PLTE?z=ڀIDATx?c`? ?ӻ?ND?B`?

I whould be glad if you help me. :help:
regards
User avatar
lisham
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Mar 29, 2004 2:07 am
Location: IR. Tehran

Postby swirlee » Mon Mar 29, 2004 12:21 pm

Make sure you don't have anything in the code before your opening <?php tag, not even spaces or blank lines.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

ThNx I found it

Postby lisham » Mon Mar 29, 2004 8:11 pm

ThnX a lot for your reply, I found my mistake yesterday, after I posted my message. I chenged 'output_buffering' status in php.ini from 'off' to 'on' and it's right now...
best regards :-D
User avatar
lisham
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Mar 29, 2004 2:07 am
Location: IR. Tehran

Re: ThNx I found it

Postby swirlee » Mon Mar 29, 2004 8:17 pm

lisham wrote:I chenged 'output_buffering' status in php.ini from 'off' to 'on' and it's right now...


This is a kludge at best and will probably degrade the overall performance of your web site. You're a lot better off actually fixing the errors.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby lisham » Mon Mar 29, 2004 9:08 pm

TNX again, I <? echo str_rot13('EGSZ'); ?> and also I checked my code for any spaces or blank lines befor <? and I remarked header line for create jpg and I chenged back 'output_buffering' status to 'off' and also I do something like cleaning my Monitor, brushing my teeth , ... BUT :shock: aNyway! the code display images as TXT ...
Code:
[code]<?php
header ("Content-type: image/png");
$im = imagecreate (50, 50);
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 233, 14, 91);
imagestring ($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng ($im);
imagedestroy ($im);
?>[/code]Result:

[b]Warning: Cannot modify header information - headers already sent by (output started at f:\inetpub\wwwroot\php\test\gallery\image1.php:1) in f:\inetpub\wwwroot\php\test\gallery\image1.php on line 2
?PNG  IHDR22$��PLTE?[?˝?8IDATx?c` 03IEND?B`?[/b]

BeReg
User avatar
lisham
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Mar 29, 2004 2:07 am
Location: IR. Tehran

I GoT it!

Postby lisham » Tue Mar 30, 2004 2:43 am

My codes have stor with utf-8 character set, I saved them as ansi character set and the problem was solved. ThanX again for your help.
L# :D
User avatar
lisham
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Mar 29, 2004 2:07 am
Location: IR. Tehran


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.