Resize af billede bliver til en sort baggrund
Jeg ved ikke lige helt hvad der sker, men når jeg resizer et billede med det her jeg har sat sammen, bliver billederne kun sorte hmm..Hvad er årsagen til det, nogle forslag til hvordan jeg kan ændre det?
public static function imageResize($img, $max_size, $max_width, $max_height, $destination, $img_name)
{
// Upload the image temporary
$tempID = $img_name;//rand(5, 15);
ImageHandler::uploadImage($img, self::$temp, $tempID);
$img_format = ImageHandler::getImageFormat($img);
$img_source = self::$temp.$tempID.".".$img_format;
//echo $img_source;
if($img_format == "jpg" || $img_format == "JPG" )
$img_format = "jpeg";
list($width, $height, $format) = getimagesize($img_source);
$imagecreatefrom_format = "imagecreatefrom".$img_format;
$image_format = "image".$img_format;
if($img_src = $imagecreatefrom_format($img_source))
{
$new_width = $width;
$new_height = $height;
if($max_width != 0 && $max_width < $width)
{
$new_width = ($max_width / $width)*$width;
$new_height = ($max_width / $width)*$height;
}
if($max_height != 0 && $max_height < $height)
{
$new_width = ($max_height / $height)*$width;
$new_height = ($max_height / $height)*$height;
}
//echo "width=".$new_width." height=".$new_height;
$img_dst = imagecreatetruecolor($new_width, $new_height);
$black = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent($img_dst, $black);
imagecopyresampled($img_dst, $img_source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
$image_format($img_dst, $destination.$tempID.".".$img_format);
imagedestroy($img_dst);
}
}