cooldude832 Posted October 14, 2007 Share Posted October 14, 2007 I made this <?php $img_types = array("image/jpg", "image/pjpg", "image/jpeg", "iamge/pjpeg"); $new_path = ROOT."graphics/facilitators/".$_SESSION['FacID'].".jpg"; if (in_array($_FILES['image']['type'], $img_types)){ if(copy ($_FILES['image']['tmp_name'], $new_path)){ $target = 150; if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); $imgdata = getimagesize($new_path); $thumb = ImageCreateTrueColor(150, 150); list($width, $height) = getimagesize($new_path); imagecopyresized($thumb, $new_path, 0, 0, 0, 0, 150, 150, $width, $height); imagejpeg($thumb,$new_path); ?> which uploads and moves 100% fine if I don't resize, but as soon as I added the resize It just outputs a black 150x150 as the image. Any ideas?? Quote Link to comment https://forums.phpfreaks.com/topic/73161-image-resize-returning-a-black-image/ Share on other sites More sharing options...
cooldude832 Posted October 14, 2007 Author Share Posted October 14, 2007 solved it forgot I needed to use the img data and not the actual file source this is the whole thing if anyone wants it <?php $img_types = array("image/jpg", "image/pjpg", "image/jpeg", "iamge/pjpeg"); $new_path = ROOT."graphics/facilitators/".$_SESSION['FacID'].".jpg"; if (in_array($_FILES['image']['type'], $img_types)){ if(copy ($_FILES['image']['tmp_name'], $new_path)){ $target = 150; if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); $imgdata = getimagesize($new_path); $thumb = ImageCreateTrueColor(150, 150); list($width, $height) = getimagesize($new_path); $source = imagecreatefromjpeg($new_path); imagecopyresized($thumb, $source, 0, 0, 0, 0, 150, 150, $width, $height); imagejpeg($thumb,$new_path,100); ?> Quote Link to comment https://forums.phpfreaks.com/topic/73161-image-resize-returning-a-black-image/#findComment-369032 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.