evanct Posted July 4, 2009 Share Posted July 4, 2009 I have an image resize function that scales an image to a width of 800px if it's too big. It's been outputting a solid black image of the correct dimensions. What's strange is that my thumbnail function is virtually identical to it, yet it works perfectly. I've tried several images of several different filetypes and it's always the same result. <?php function imgCreate($ext,$image) { switch ($ext) { case 'jpg': case 'jpeg': $img=imagecreatefromjpeg($image); break; case 'png': $img=imagecreatefrompng($image); break; case 'gif': $img=imagecreatefromgif($image); break; } return $img; } function saveImg($ext,$img,$path) { switch ($ext) { case 'jpg': case 'jpeg': imagejpeg($img,$path,JPEG_QUALITY); break; case 'png': imagepng($img,$path); break; case 'gif': imagegif($img,$path); break; } } function resizeImage($image,$filename,$path,$ext,$ratio) { $tmp=$this->imgCreate($ext,$image); $newwidth=MAX_IMAGE_WIDTH; $newheight=$newwidth*$ratio; $img=imagecreatetruecolor($newwidth,$newheight); imagecopyresampled($img,$tmp,0,0,0,0,$newwidth,$newheight,$width,$height); $this->saveImg($ext,$img,$path.'/'.$filename); } function makeThumbnail($image,$filename,$path,$ext,$tn_width,$tn_height) { $tmp=$this->imgCreate($ext,$image); // some size and coords calculations here, not relevant // $img=imagecreatetruecolor(TN_SIZE,TN_SIZE); imagecopyresampled($img,$tmp,0,0,$x,$y,TN_SIZE,TN_SIZE,$tn_width,$tn_height); $this->saveImg($ext,$img,$path.'/'.$filename); } } ?> any ideas? Link to comment https://forums.phpfreaks.com/topic/164720-solved-gd-creates-black-image/ Share on other sites More sharing options...
evanct Posted July 4, 2009 Author Share Posted July 4, 2009 Oh, duh. I didn't pass $width and $height to resizeImage. careless... Link to comment https://forums.phpfreaks.com/topic/164720-solved-gd-creates-black-image/#findComment-868640 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.