ccrevcypsys Posted August 30, 2007 Share Posted August 30, 2007 Some one i am begging for you to help me figure this out. I just dont understand why it isnt working. Like i have said before i am a n00b but i am learning alot. Back to the matter at hand. Ok so heres whats going on. Every time i try to upload an image it has a save error when it tries to save it into the thumb directory heres the err msg Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/streamru/public_html/classes/gd.inc.php on line 273 Warning: fclose(): supplied argument is not a valid stream resource in /home/streamru/public_html/classes/gd.inc.php on line 289 Warning: imagegif(): supplied argument is not a valid Image resource in /home/streamru/public_html/classes/gd.inc.php on line 307 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/streamru/public_html/classes/gd.inc.php on line 310 save error I figured that the gd class wouldnt work because of the save error at the end. Heres the code for the upload part: if(is_array($_FILES['imageName'])){ $date_str=date('Ymdhistis'); $imageFormat = strtoupper(ereg_replace(".*\.(.*)$","\\1",$_FILES['imageName']['name'])); if($imageFormat == "JPG" || $imageFormat == "JPEG" || $imageFormat == "PNG" || ($imageFormat == "GIF" && $config['gdGifSupport']==1)){ copy($_FILES['imageName']['tmp_name'],"images/uploads/".$date_str."_".str_replace(' ','_',$_FILES['imageName']['name'])) or die("| copy error |"); $record["image"] = $db->mySQLSafe($date_str."_".$_FILES['imageName']['name']); copy($_FILES['imageName']['tmp_name'],"images/uploads/thumbs/thumb_".$date_str."_".str_replace(' ','_',$_FILES['imageName']['name'])) or die("| copy 2 Thumb error |"); if(file_exists($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$date_str."_".str_replace(' ','_',$_FILES['imageName']['name']))){ @chmod($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$date_str."_".str_replace(' ','_',$_FILES['imageName']['name']), 0775); unlink($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$date_str."_".str_replace(' ','_',$_FILES['imageName']['name'])); } $thumb=new thumbnail("images/uploads/".$date_str."_".$_FILES['imageName']['name']); // see if we need to resize if(($size[0] > $config['gdthumbSize']) OR ($size[1] > $config['gdthumbSize'])){ $thumb->size_auto($config['gdthumbSize']); } else { $thumb->size_auto($size[0]); } $thumb->jpeg_quality($config['gdquality']); $thumb->save("images/uploads/thumbs/thumb_".$date_str."_".str_replace(' ','_',$_FILES['imageName']['name'])) or die("save error"); } } Now here is the code from the gd class (it is a lot of code but i really need this to work.) <?php class thumbnail { var $img; function thumbnail($imgfile="",$width="",$height="") { global $config; //detect image format $this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile); $this->img["format"]=strtoupper($this->img["format"]); if($config['gdversion']>0) { if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG $this->img["format"]="JPG"; $this->img["src"] = imagecreatefromjpeg($imgfile); } elseif($this->img["format"]=="PNG") { //PNG $this->img["format"]="PNG"; $this->img["src"] = imagecreatefrompng($imgfile); } elseif ($this->img["format"]=="GIF") { //GIF $this->img["format"]="GIF"; $this->img["src"] = imagecreatefromgif($imgfile); } else { //DEFAULT echo "Not Supported File!"; exit(); } if($width>0 && $height>0) { $this->img["width"] = $width; $this->img["height"] = $height; } else { @$this->img["width"] = imagesx($this->img["src"]); @$this->img["height"] = imagesy($this->img["src"]); } //default quality jpeg $this->img["quality"] = $config['gdquality']; } else { return FALSE; } } function size_custom($width=100, $height=100) { // custom $this->img["width_thumb"] = $width; $this->img["height_thumb"] = $height; } function size_width($size=200) { // width $this->img["width_thumb"]=$size; @$this->img["height_thumb"] = ($this->img["width_thumb"]/$this->img["width"])*$this->img["height"]; } function size_height($size=200) { // height $this->img["height_thumb"]=$size; @$this->img["width_thumb"] = ($this->img["height_thumb"]/$this->img["height"])*$this->img["width"]; } function size_auto($size=200) { // size automatically if ($this->img["width"]>=$this->img["height"]) { $this->img["width_thumb"]=$size; @$this->img["height_thumb"] = ($this->img["width_thumb"]/$this->img["width"])*$this->img["height"]; } else { $this->img["height_thumb"]=$size; @$this->img["width_thumb"] = ($this->img["height_thumb"]/$this->img["height"])*$this->img["width"]; } } function jpeg_quality($quality=80) { //jpeg quality $this->img["quality"]=$quality; } function randImage($rand) { global $glob; $bgColor = imagecolorallocate ($this->img["src"], 255, 255, 255); $textColor = imagecolorallocate ($this->img["src"], 0, 0, 0); $lineColor = imagecolorallocate ($this->img["src"], 215, 215, 215); // Add Random polygons $noise_x = $this->img["width"] - 5; $noise_y = $this->img["height"] - 2; for ($i=0; $i<3; $i++){ $polyCoords = array( rand(5,$noise_x), rand(5,$noise_y), rand(5,$noise_x), rand(5,$noise_y), rand(5,$noise_x), rand(5,$noise_y), rand(5,$noise_x), rand(5,$noise_y), rand(5,$noise_x), rand(5,$noise_y), rand(5,$noise_x), rand(5,$noise_y), rand(5,$noise_x), rand(5,$noise_y), rand(5,$noise_x), rand(5,$noise_y), rand(5,$noise_x), rand(5,$noise_y), rand(5,$noise_x), rand(5,$noise_y), rand(5,$noise_x), rand(5,$noise_y), rand(5,$noise_x), rand(5,$noise_y) ); $randomcolor = imagecolorallocate( $this->img["src"], rand(150,255), rand(150,255),rand(150,255) ); imagefilledpolygon($this->img["src"], $polyCoords, 6, $randomcolor); } // write the random chars $font = imageloadfont($glob['rootDir']."/classes/fonts/anonymous.gdf"); imagestring($this->img["src"], $font, 3, 0, $rand, $textColor); // Add Random noise for ($i = 0; $i < 25; $i++) { $rx1 = rand(0,$this->img["width"]); $rx2 = rand(0,$this->img["width"]); $ry1 = rand(0,$this->img["height"]); $ry2 = rand(0,$this->img["height"]); $rcVal = rand(0,255); $rc1 = imagecolorallocate($this->img["src"],rand(0,255),rand(0,255),rand(100,255)); imageline ($this->img["src"], $rx1, $ry1, $rx2, $ry2, $rc1); } $this->show(1); } function show($skip=0) { global $config; @header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT"); @header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); @header("Cache-Control: no-store, no-cache, must-revalidate"); @header("Cache-Control: post-check=0, pre-check=0", false); @header("Pragma: no-cache"); @header("Content-Type: image/".$this->img["format"]); if($skip==1) { $this->img["des"] = $this->img["src"]; } elseif ($config['gdversion']==2) { $this->img["des"] = imagecreatetruecolor($this->img["width_thumb"],$this->img["height_thumb"]); @imagecopyresampled ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["width_thumb"],$this->img["height_thumb"], $this->img["width"], $this->img["height"]); } elseif ($config['gdversion']==1) { $this->img["des"] = imagecreate($this->img["width_thumb"],$this->img["height_thumb"]); @imagecopyresized ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["width_thumb"],$this->img["height_thumb"], $this->img["width"], $this->img["height"]); } if ($config['gdversion']>0) { // fix for base restriction error $fh = fopen($this->img["des"],'w'); fclose($fh); if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG imagejpeg($this->img["des"],"",$this->img["quality"]); } elseif($this->img["format"]=="PNG") { //PNG imagepng($this->img["des"]); } elseif($this->img["format"]=="GIF") { //GIF imagegif($this->img["des"]); } imagedestroy($this->img["des"]); } } function save($save="") { global $config; if ($config['gdversion']==2) { $this->img["des"] = imagecreatetruecolor($this->img["width_thumb"],$this->img["height_thumb"]); @imagecopyresampled ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["width_thumb"], $this->img["height_thumb"], $this->img["width"], $this->img["height"]); } elseif ($config['gdversion']==1) { $this->img["des"] = imagecreate($this->img["width_thumb"],$this->img["height_thumb"]); @imagecopyresized ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["width_thumb"], $this->img["height_thumb"], $this->img["width"], $this->img["height"]); } if ($config['gdversion']>0) { $fh = fopen($this->img["des"],'w'); fclose($fh); if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG imagejpeg($this->img["des"],$save,$this->img["quality"]); } elseif ($this->img["format"]=="PNG") { //PNG imagepng($this->img["des"],$save); } elseif ($this->img["format"]=="GIF") { //GIF imagegif($this->img["des"],$save); } imagedestroy($this->img["des"]); @chmod($this->img["des"], 0644); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67368-omg-im-going-to-shoot-myself/ Share on other sites More sharing options...
ccrevcypsys Posted August 30, 2007 Author Share Posted August 30, 2007 also it uploads to the server just fine just doesnt move it into the thumbs dir heres a pic but jpgs dont work at all Quote Link to comment https://forums.phpfreaks.com/topic/67368-omg-im-going-to-shoot-myself/#findComment-338000 Share on other sites More sharing options...
teng84 Posted August 30, 2007 Share Posted August 30, 2007 echo fist the parameter that is being supplied in your imagecreatetruecolor to know whether the value are correct Quote Link to comment https://forums.phpfreaks.com/topic/67368-omg-im-going-to-shoot-myself/#findComment-338013 Share on other sites More sharing options...
ccrevcypsys Posted August 30, 2007 Author Share Posted August 30, 2007 it said this Object id #6 wtf Quote Link to comment https://forums.phpfreaks.com/topic/67368-omg-im-going-to-shoot-myself/#findComment-338030 Share on other sites More sharing options...
ccrevcypsys Posted August 30, 2007 Author Share Posted August 30, 2007 ok so i did another echo and go this images/uploads/thumbs/thumb_20070830043354killthegods.gif but its not uploaded in the thumbs directory its only in the uploads. It is supposted to create a thumb nail into the thumbs direct it looks like to me that it would work. i just dont get it Quote Link to comment https://forums.phpfreaks.com/topic/67368-omg-im-going-to-shoot-myself/#findComment-338031 Share on other sites More sharing options...
ccrevcypsys Posted August 30, 2007 Author Share Posted August 30, 2007 it is now uploading to the server but it is giving me those errors still Quote Link to comment https://forums.phpfreaks.com/topic/67368-omg-im-going-to-shoot-myself/#findComment-338040 Share on other sites More sharing options...
teng84 Posted August 30, 2007 Share Posted August 30, 2007 if those codes functioning properly just add the @ to remove those warning Quote Link to comment https://forums.phpfreaks.com/topic/67368-omg-im-going-to-shoot-myself/#findComment-338042 Share on other sites More sharing options...
ccrevcypsys Posted August 30, 2007 Author Share Posted August 30, 2007 it still doesnt create thumb of jpg or jpeg works for png and gif Quote Link to comment https://forums.phpfreaks.com/topic/67368-omg-im-going-to-shoot-myself/#findComment-338045 Share on other sites More sharing options...
ccrevcypsys Posted August 30, 2007 Author Share Posted August 30, 2007 the warning i get with a jpg upload Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/streamru/public_html/classes/gd.inc.php on line 300 Quote Link to comment https://forums.phpfreaks.com/topic/67368-omg-im-going-to-shoot-myself/#findComment-338052 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.