Jump to content

[SOLVED] GD woes - pngs and gifs create black images


evanct

Recommended Posts

I have this script to resize an uploaded image. It all works fine as long as I upload a jpeg. If the image is png or gif, a 100% black image is created. The black image is resized to the correct dimensions, saved to the correct folder with the correct filename and extension - it's just that it's black. setting error_reporting to E_ALL reveals nothing.

 

the relevant code:

 

<?php

function imgCreate($ext,$tmp) {
switch ($ext) {
	case 'jpg' || 'jpeg': $img=imagecreatefromjpeg($tmp);
	break;
	case 'png': $img=imagecreatefrompng($tmp);
	break;
	case 'gif': $img=imagecreatefromgif($tmp);
	break;
}
return $img;
}

function saveImg($ext,$tmpimg,$tn_path) {
switch($ext) {
	case 'jpg' || 'jpeg': imagejpeg($tmpimg,$tn_path,JPEG_QUALITY);
	break;
	case 'png': imagepng($tmpimg,$tn_path);
	break;
	case 'gif': imagegif($tmpimg,$tn_path);
	break;
}
}

function resizeImage($tmp,$filename,$ext,$width,$height) {
$img=imgCreate($ext,$tmp);
$path='../'.IMAGE_DIR.$filename;
if ($width > $height) {
	$newwidth=MAX_IMAGE_SIZE;
	$newheight=$newwidth*($height/$width);
} else if ($height > $width) {
	$newheight=MAX_IMAGE_SIZE;
	$newwidth=$newheight*($width/$height);
} else if ($height==$width) {
	$newheight=$newwidth=MAX_IMAGE_SIZE;
}
$tmpimg=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmpimg,$img,0,0,0,0,$newwidth,$newheight,$width,$height);
saveImg($ext,$tmpimg,$path);
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.