проблемы с отправкой header

  • Автор темы Автор темы saiman
  • Дата начала Дата начала

saiman

Новичок
проблемы с отправкой header

есть код вида:

Код:
$src=ImageCreateFromJpeg($image);  

$width=imagesx ($src);
$height=imagesy($src);
$type=strrchr($image, '.');

$dst = ImageCreate($main_width,$main_height);
imagecopyresampled($dst,$src,0,0,0,0,$main_width,$main_height,$width,$height);

       if (function_exists("imagegif")) {
    header ("Content-type: image/gif");
    imagegif ($dst);
}
elseif (function_exists("imagejpeg")) {
    header ("Content-type: image/jpeg");
    imagejpeg ($dst, "", 0.5);
}
elseif (function_exists("imagepng")) {
    header ("Content-type: image/png");
    imagepng ($dst);
}
elseif (function_exists("imagewbmp")) {
    header ("Content-type: image/vnd.wap.wbmp");
    imagewbmp ($dst);
}
else  {
    die("No image support in this PHP server");
}

но почему то в браузер выводит не изображение, а набор символов.
я так предпологаю что преблемы с header или с библиотекой GD но разобратся не могу
за ранее благодарен..
 
посмотри листнером заголовкови и если там всё хорошо - то тогда это проблема.
с библиотекой GD таких проблем НЕТ!
 
imagejpeg ($dst, "", 0.5);
The filename argument is optional, and if left off, the raw image stream will be output directly. To skip the filename argument in order to provide a quality argument just use a NULL value. By sending an image/jpeg content-type using header(), you can create a PHP script that outputs JPEG images directly.

и лучше делать imagecreatetruecolor()
 
проблема в том что даже элементарный код ито не работает
Код:
$src=ImageCreateFromJpeg($image);
  header ("Content-type: image/jpeg");
 imagejpeg ($src);
 
Слушай, а вот:
Код:
$src=ImageCreateFromJpeg($image);

А откуда такая уверенность, что $image - это JPEG?

Попробуй такой код:
Код:
error_reporting(E_ALL);
$src=ImageCreateFromJpeg($image);  

if(!$src) die();

$width=imagesx ($src);
$height=imagesy($src);
$type=strrchr($image, '.');

$dst = ImageCreate($main_width,$main_height);
imagecopyresampled($dst,$src,0,0,0,0,$main_width,$main_height,$width,$height);

       if (function_exists("imagegif")) {
    header ("Content-type: image/gif");
    imagegif ($dst);
}
elseif (function_exists("imagejpeg")) {
    header ("Content-type: image/jpeg");
    imagejpeg ($dst, "", 0.5);
}
elseif (function_exists("imagepng")) {
    header ("Content-type: image/png");
    imagepng ($dst);
}
elseif (function_exists("imagewbmp")) {
    header ("Content-type: image/vnd.wap.wbmp");
    imagewbmp ($dst);
}
else  {
    die("No image support in this PHP server");
}

Например для $image = "./1.gif", PHP ругается:
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in xxx\_test.php on line 4

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: './1.gif' is not a valid JPEG file in xxx\_test.php on line 4
 
http://www.kvorum-auto.com/?page=autophoto&id=44&marka=Mazda&model=3
пожалуйста...

-~{}~ 21.12.06 17:12:

выдает что то в роде
Warning: Cannot modify header information - headers already sent by (output started at /home.....

но это "jpg"
 
:))) сильно!

У тебя уже кто-то отправляет заголовок. посмотри, мож в начале файла пробелы стоят или ещё какой-нить вывод.
 
saiman
вот-вот-вот. Это jpg. А вот тот error-message, который ты любезно обрезал, говорит тебе о том, что ты не слушаешь, что тебе говорит PHP. Внимательно погляди на этот варнинг и, если не поймешь, сходи почитай про особенность приминения header();

А надеяться на "но это jpg" не надо. Есть http://php.net/getimagesize Ошибки обрабатывай получше.

-~{}~ 22.12.06 00:21:

из http://php.net/header

Note: The HTTP status header line will always be the first sent to the client, regardless of the actual header() call being the first or not. The status may be overridden by calling header() with a new status line at any time unless the HTTP headers have already been sent.

-~{}~ 22.12.06 00:21:

Vallar_ultra
Да уж, уже и бедный GD2 виноват =))

-~{}~ 22.12.06 00:24:

ВО: http://phpfaq.ru/headers
 
Сверху