evanct Posted May 21, 2009 Share Posted May 21, 2009 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); } ?> Link to comment https://forums.phpfreaks.com/topic/159161-solved-gd-woes-pngs-and-gifs-create-black-images/ Share on other sites More sharing options...
evanct Posted May 21, 2009 Author Share Posted May 21, 2009 Something about case 'jpg' || 'jpeg': was causing it to do imagecreatefromjpeg regardless of $ext. I guess you can't use the or operator in switch conditionals? Link to comment https://forums.phpfreaks.com/topic/159161-solved-gd-woes-pngs-and-gifs-create-black-images/#findComment-839423 Share on other sites More sharing options...
.josh Posted May 21, 2009 Share Posted May 21, 2009 wrap it in parenthesis. Link to comment https://forums.phpfreaks.com/topic/159161-solved-gd-woes-pngs-and-gifs-create-black-images/#findComment-839444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.