jwk811 Posted April 30, 2010 Share Posted April 30, 2010 im trying to loop thru all the photos i have here but i get this error. (its not the db_fetch_assoc or db_query) it works when im not using the resize function but that function works when im not looping thru the database. Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/content/p/o/k/pokher366/html/photos/program.php on line 37 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/p/o/k/pokher366/html/lib/config.php on line 76 function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { $s_path = trim($s_path); $o_path = trim($o_path); $save = $s_path . $save; $file = $o_path . $file; $ext = strtolower(end(explode('.',$save))); list($width, $height) = getimagesize($file) ; if(($width>$t_w) OR ($height>$t_h)) { $r1 = $t_w/$width; $r2 = $t_h/$height; if($r1<$r2) { $size = $t_w/$width; }else{ $size = $t_h/$height; } }else{ $size=1; } $modwidth = $width * $size; $modheight = $height * $size; $tn = imagecreatetruecolor($modwidth, $modheight) ; switch ($ext) { case 'jpg': case 'jpeg': $image = imagecreatefromjpeg($file) ; break; case 'gif': $image = imagecreatefromgif($file) ; break; case 'png': $image = imagecreatefrompng($file) ; break; } imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; return; } $sql = "SELECT * FROM photo_posts ORDER BY post_date DESC"; $result = dbQuery($sql); while($row = dbFetchAssoc($result)) { extract($row); $thumbPath = md5(rand() * time()) . ".$ext"; $save = $thumbPath; $file = $post_image; $t_w = 180; $t_h = 800; $o_path = "images/"; $s_path = "images/thumbs/"; if (file_exists($o_path . $post_image)) { Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path); $sql = "UPDATE photo_posts SET post_thumbnail = '$thumbPath' WHERE post_id = '$post_id'"; $result = dbQuery($sql); } } Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 30, 2010 Share Posted April 30, 2010 I'm guessing one of the "images" in the DB query is not an image or has the wrong extension. FYI: A jpg with a gif extension will typically display in most applications but would fail if you tried to read it as a jpg in PHP. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted April 30, 2010 Author Share Posted April 30, 2010 maybe because some are capital JPG and some are jpg? if so how could i change that in the code so it allows both. all the photos in the directory are jpg and a couple gif Quote Link to comment Share on other sites More sharing options...
jwk811 Posted April 30, 2010 Author Share Posted April 30, 2010 nevermind. i checked the directory again today and all the files are copied like they were supposed to. weird. only one problem theres 704 in the new directory but 714 in the old. i wonder why 10 failed. Quote Link to comment 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.