ændre baggr. farve
Hej.Jeg har et script der laver udsnit af billeder, men når billedet er mindre end $imagethumbsize så kommer der en sort baggrund. Er det ikke muligt at ændre den til hvid, og hvis ja, hvordan gør jeg det ???
<?php
$filename = "/customers/sti.dk/sti.dk/httpd.www/test/".$_GET['filnavn'];
$info = getimagesize( $filename );
$percent = 0.5; // if you want to scale down first
$imagethumbsize = 50; // thumbnail size (area cropped in middle of image)
switch ( $info[2] )
{
case 1:
// gif
// Content type
header('Content-type: image/gif');
// Get new dimensions
list($width, $height) = getimagesize($filename);
if ($width<100 or $height<100) {
$new_width = $width ;
$new_height = $height ; }
else {
$new_width = $width * $percent;
$new_height = $height * $percent; }
// Resample
$image_p = imagecreate($imagethumbsize , $imagethumbsize); // true color for best quality
$image = imagecreatefromgif($filename);
// basically take this line and put in your versin the -($new_width/2) + ($imagethumbsize/2) & -($new_height/2) + ($imagethumbsize/2) for
// the 2/3 position in the 3 and 4 place for imagecopyresampled
// -($new_width/2) + ($imagethumbsize/2)
// AND
// -($new_height/2) + ($imagethumbsize/2)
// are the trick
imagecopyresampled($image_p, $image, -($new_width/2) + ($imagethumbsize/2), -($new_height/2) + ($imagethumbsize/2), 0, 0, $new_width , $new_height , $width, $height);
break;
case 2:
// jpeg
// Content type
header('Content-type: image/jpg');
// Get new dimensions
list($width, $height) = getimagesize($filename);
if ($width<100 or $height<100) {
$new_width = $width;
$new_height = $height; }
else {
$new_width = $width * $percent;
$new_height = $height * $percent; }
// Resample
$image_p = imagecreatetruecolor($imagethumbsize , $imagethumbsize); // true color for best quality
$image = imagecreatefromjpeg($filename);
// basically take this line and put in your versin the -($new_width/2) + ($imagethumbsize/2) & -($new_height/2) + ($imagethumbsize/2) for
// the 2/3 position in the 3 and 4 place for imagecopyresampled
// -($new_width/2) + ($imagethumbsize/2)
// AND
// -($new_height/2) + ($imagethumbsize/2)
// are the trick
imagecopyresampled($image_p, $image, -($new_width/2) + ($imagethumbsize/2), -($new_height/2) + ($imagethumbsize/2), 0, 0, $new_width , $new_height , $width, $height);
break;
default:
die( 'Ikke understøttet. Vi tager kun imod jpg og gif!' );
}
switch ( $info[2] )
{
case 1:
imagegif($image_p);
break;
case 2:
imagejpeg($image_p, null, 100);
break;
}
?>
