Not valid JPG!!!

Alles, was PHP betrifft, kann hier besprochen werden.

Not valid JPG!!!

Postby Mr.Guest » 16. June 2005 23:20

I have this code :

<?php
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $timestamp).' GMT');
header('Content-Type: image/jpeg');


include("config.php") ;


$image = $path_default . $_GET['image'];


if (!$max_width)
$max_width= 170;
if (!$max_height)
$max_height=140;
$size = getimagesize($image);

if(!$size) {
$image = ImageCreate(170,140);
$bgc = ImageColorAllocate($image, 255, 255, 255);
$tc = ImageColorAllocate($image, 0, 0, 0);
ImageFilledRectangle($image, 0, 0, 200, 30, $bgc);
ImageString($image, 5, 47, 53, "NENALEZENO", $tc);
$image = imagejpeg($image);
}

$size = @getimagesize($image);


$width= $size[0];
$height= $size[1];

$x_ratio= $max_width / $width;
$y_ratio=$max_height / $height;

if (($width <= $max_width)&&($height <= $max_height)){
$tn_width = $width;
$tn_height = $height;}
else
if (($width * $height) < $max_height){
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;}
else{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;}

$scr = imagecreatefromjpeg($image);

$dts = imagecreatetruecolor($tn_width,$tn_height);
imagecopyresampled($dts,$scr,0,0,0,0,$tn_width,$tn_height,$width,$height);
imagejpeg($dts,null,-1);
imagedestroy($scr);
imagedestroy($dts);


?>


bad this code return me not valid JPG!!!! If I upload into some server (maby www.webzdarma.cz) it all OK, but if I test in my localhost picture is bat.
At the start this HEXA "0D 0A 0D 0A". Bad this is not valid JPEG and IE, FireFx etc. dont display it!!!! Where is mistakes??? php_gd2.dll mayby???
Mr.Guest
 
Posts: 5
Joined: 12. June 2005 15:12

Postby jakimo72 » 19. June 2005 11:40

Die Variable $timestamp kann zu dem Zeitpunkt
der Ausführung noch nicht definiert sein.
Wenn $timestamp in 'config.php' definiert ist, so muss
diese Datei vor der ersten Zeile eingebunden werden.

Du lässt Dir alle Fehler, Warnungen und Notices anzeigen,
deshalb kannst Du auch wunderbar im Sourcecode der
erzeugten Graphic sehen, dass dort steht:
<b>Notice</b>: Undefined variable: timestamp in <b>/home/achim/public_html/phptest/loadjpg.php</b> on line <b>2</b><br />
User avatar
jakimo72
 
Posts: 151
Joined: 07. February 2005 13:25
Location: Hamburg-Barmbek

Postby adi99 » 19. June 2005 12:47

@jakimo72: er hat auf englisch geschrieben, darum wird er wohl kaum Deutsch verstehen

@Mr.Guest: You have to define $timestamp !

Code: Select all
    
<?php
$timestamp = time();
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $timestamp).' GMT');
header('Content-Type: image/jpeg');


include("config.php") ;


$image = $path_default . $_GET['image'];


if (!$max_width)
$max_width= 170;
if (!$max_height)
$max_height=140;
$size = getimagesize($image);

if(!$size) {
$image = ImageCreate(170,140);
$bgc = ImageColorAllocate($image, 255, 255, 255);
$tc = ImageColorAllocate($image, 0, 0, 0);
ImageFilledRectangle($image, 0, 0, 200, 30, $bgc);
ImageString($image, 5, 47, 53, "NENALEZENO", $tc);
$image = imagejpeg($image);
}

$size = @getimagesize($image);


$width= $size[0];
$height= $size[1];

$x_ratio= $max_width / $width;
$y_ratio=$max_height / $height;

if (($width <= $max_width)&&($height <= $max_height)){
$tn_width = $width;
$tn_height = $height;}
else
if (($width * $height) < $max_height){
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;}
else{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;}

$scr = imagecreatefromjpeg($image);

$dts = imagecreatetruecolor($tn_width,$tn_height);
imagecopyresampled($dts,$scr,0,0,0,0,$tn_width,$tn_height,$width,$height);
imagejpeg($dts,null,-1);
imagedestroy($scr);
imagedestroy($dts);


?>
User avatar
adi99
 
Posts: 115
Joined: 15. January 2004 16:08
Location: Switzerland


Return to PHP

Who is online

Users browsing this forum: No registered users and 47 guests