Jump to content

error when resizing images


jwk811

Recommended Posts

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);
}

}

 

 

Link to comment
https://forums.phpfreaks.com/topic/200240-error-when-resizing-images/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.