Imagejpg geeft tekens
Tony_mortana - 07/11/2006 19:14
PHP interesse
Bij gebruik ban Imagejpg (voor thumnails te maken) krijg ik alleen maar vreemde tekens in beeld ipv een afbeelding.
kan iemand mij vertellen hoe dat komt?
PS: er draaid GD 2.0...... op.
2 standaard codes geprobeerd, beide geven ze tekens.
function LoadJpeg($imgname)
{
$im = @imagecreatefromjpeg($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetruecolor(150, 30); /* Create a black image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
} else {
echo "faut";
}
return $im;
}
imagejpeg(LoadJpeg('./upload/test.jpg'));
function LoadJpeg( $imgname )
{
$im = @ imagecreatefromjpeg( $imgname ) ; /* Attempt to open */
if ( ! $im ) { /* See if it failed */
$im = imagecreatetruecolor( 150 , 30 ) ; /* Create a black image */
$bgc = imagecolorallocate( $im , 255 , 255 , 255 ) ;
$tc = imagecolorallocate( $im , 0 , 0 , 0 ) ;
imagefilledrectangle( $im , 0 , 0 , 150 , 30 , $bgc ) ;
/* Output an errmsg */
imagestring( $im , 1 , 5 , 5 , "Error loading $imgname " , $tc ) ;
} else {
}
return $im ;
}
imagejpeg( LoadJpeg( './upload/test.jpg' ) ) ;
of
function tumb_creat($file)
{
// File and new size
$filename = '../upload/'.$file;
$percent = 0.5;
$var = 100;
// Content type
header('Content-type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
if ($width > $height)
{
$newwidth = $width / ($width/$var);
$newheight = $height / ($width/$var);
} else {
$newheight = $height / ($height/$var);
$newwidth = $width / ($height/$var);
}
$newheight = 100;
$newwidth = 100;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
}
tumb_creat("test.jpg");
function tumb_creat( $file )
{
// File and new size
$filename = '../upload/' . $file ;
$percent = 0.5 ;
$var = 100 ;
// Content type
header ( 'Content-type: image/jpeg' ) ;
// Get new sizes
if ( $width > $height )
{
$newwidth = $width / ( $width / $var ) ;
$newheight = $height / ( $width / $var ) ;
} else {
$newheight = $height / ( $height / $var ) ;
$newwidth = $width / ( $height / $var ) ;
}
$newheight = 100 ;
$newwidth = 100 ;
// Load
$thumb = imagecreatetruecolor( $newwidth , $newheight ) ;
$source = imagecreatefromjpeg( $filename ) ;
// Resize
imagecopyresized( $thumb , $source , 0 , 0 , 0 , 0 , $newwidth , $newheight , $width , $height ) ;
// Output
imagejpeg( $thumb ) ;
}
tumb_creat( "test.jpg" ) ;
4 antwoorden
Gesponsorde links
Tony_mortana - 07/11/2006 19:55
PHP interesse
Ja bedankt, heb nu de code werkend.
Alleen zodra ik het ik in een gewone HTML pagina gooi,
dan krijg ik weer de tekens
Waar mot ik die header neerzetten, meerder dingen geprobeerd,
maar het werkt allemaal niet.
PS: deze functie werkt nu bij mij!
header ("Content-type: image/png");
function tumb_creat($file)
{
// File and new size
$filename = '../upload/'.$file;
$percent = 0.5;
$var = 100;
// Content type
header('Content-type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
if ($width > $height)
{
$newwidth = $width / ($width/$var);
$newheight = $height / ($width/$var);
} else {
$newheight = $height / ($height/$var);
$newwidth = $width / ($height/$var);
}
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
}
tumb_creat("test.jpg");
header ( "Content-type: image/png" ) ;
function tumb_creat( $file )
{
// File and new size
$filename = '../upload/' . $file ;
$percent = 0.5 ;
$var = 100 ;
// Content type
header ( 'Content-type: image/jpeg' ) ;
// Get new sizes
if ( $width > $height )
{
$newwidth = $width / ( $width / $var ) ;
$newheight = $height / ( $width / $var ) ;
} else {
$newheight = $height / ( $height / $var ) ;
$newwidth = $width / ( $height / $var ) ;
}
// Load
$thumb = imagecreatetruecolor( $newwidth , $newheight ) ;
$source = imagecreatefromjpeg( $filename ) ;
// Resize
imagecopyresized( $thumb , $source , 0 , 0 , 0 , 0 , $newwidth , $newheight , $width , $height ) ;
// Output
imagejpeg( $thumb ) ;
}
tumb_creat( "test.jpg" ) ;
Gesponsorde links
Dit onderwerp is gesloten .