sopranolv Posted September 10, 2015 Share Posted September 10, 2015 in script i have this $target_path2 = $_SERVER['DOCUMENT_ROOT']."/uploads/"; $aname1 = basename( $_FILES['avatar']['name']); $anameExt = substr($aname1, 100); switch($anameExt) { case '.png': $papl = ".png"; break; case '.gif': $papl = ".gif"; break; default: $papl = ".jpg"; break; } $failaName = time().$papl; $target_path = $target_path2 . $failaName; move_uploaded_file($_FILES['avatar']['tmp_name'], $target_path); $ext = createThumb($target_path, "uploads/avatars/avatar_$user[id]", 550, 950); $pictureURL = "/uploads/pictures/".$faila_nosaukums; $sizes = array(25, 46, 75, 100); foreach($sizes as $size) { createThumb($target_path, "uploads/avatars/avatar_$user[id]_".$size."x".$size, $size, $size); //chmod($_SERVER['DOCUMENT_ROOT']."/uploads/avatars/avatar_$user[id]_".$size."x".$size.$ext, 0777); //echo $_SERVER['DOCUMENT_ROOT']."/uploads/avatars/avatar_$user[id]_".$size."x".$size.$ext; } unlink($target_path); $avatar=quote_smart("/uploads/avatars/avatar_".$user[id].$ext); } in functions.php i have this $row['avatar'] = $row['avatar'] == "default" ? site_url. "/style/images/avatar.png":site_url.$row['avatar']; $sizes = array(25, 46, 75, 100); foreach($sizes as $size) { if($row['avatar'] != site_url."/style/images/avatar.png") { $row['avatar_'.$size.'x'.$size] = str_replace("_$row[id]", "_$row[id]_".$size."x".$size, $row['avatar']); $row['avatar_'.$size.'x'.$size] = $row['avatar_'.$size.'x'.$size] . "?".filemtime($_SERVER['DOCUMENT_ROOT'].str_replace(site_url, '', $row['avatar_'.$size.'x'.$size])); } } if($row['avatar'] == site_url."/style/images/avatar.png") { foreach($sizes as $size) { $row['avatar_'.$size.'x'.$size] = $row['avatar']; } } else { $row['avatar'] .= "?".filemtime($_SERVER['DOCUMENT_ROOT'].str_replace(site_url, '', $row['avatar'])); } return $row; } how make this script to upload orginal size image not only the thumbs ? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 10, 2015 Share Posted September 10, 2015 The code already does upload the original size image. The script removes the original image when it has created all the thumbnails. To prevent it deleting the original image, remove unlink($target_path); Quote Link to comment Share on other sites More sharing options...
sopranolv Posted September 10, 2015 Author Share Posted September 10, 2015 ok thx work's fine and i have one more problem when I upload image turned 90 degrees why? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 10, 2015 Share Posted September 10, 2015 Is that the thumbnail images? Can you show us the code for the createThumb function? Quote Link to comment Share on other sites More sharing options...
sopranolv Posted September 10, 2015 Author Share Posted September 10, 2015 Is that the thumbnail images? Can you show us the code for the createThumb function? yes its thumbnail images function userInfo($user = '0') { if(is_numeric($user)) { $user = $user == 0 ? (int)$_COOKIE['user_id']:$user; $query = mysql_query("SELECT * FROM users WHERE id = $user"); } else { $user = quote_smart($user); $query = mysql_query("SELECT * FROM users WHERE username = $user"); } $row = mysql_fetch_array($query); if((int)$row['id'] > 0) { $posts = get_post_count_author($row['id']); mysql_query("UPDATE users SET posts = $posts WHERE id = $row[id]"); $row['posts'] = $posts; } $row['mgroup'] = (int)$row['mgroup']; $row['avatar'] = $row['avatar'] == "default" ? site_url. "/style/images/avatar.png":site_url.$row['avatar']; $sizes = array(25, 46, 75, 100); foreach($sizes as $size) { if($row['avatar'] != site_url."/style/images/avatar.png") { $row['avatar_'.$size.'x'.$size] = str_replace("_$row[id]", "_$row[id]_".$size."x".$size, $row['avatar']); $row['avatar_'.$size.'x'.$size] = $row['avatar_'.$size.'x'.$size] . "?".filemtime($_SERVER['DOCUMENT_ROOT'].str_replace(site_url, '', $row['avatar_'.$size.'x'.$size])); } } if($row['avatar'] == site_url."/style/images/avatar.png") { foreach($sizes as $size) { $row['avatar_'.$size.'x'.$size] = $row['avatar']; } } else { $row['avatar'] .= "?".filemtime($_SERVER['DOCUMENT_ROOT'].str_replace(site_url, '', $row['avatar'])); } return $row; } Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 10, 2015 Share Posted September 10, 2015 Umm.. No you posted the code user_info() function. I asked for the code for createThumb() function Quote Link to comment Share on other sites More sharing options...
sopranolv Posted September 10, 2015 Author Share Posted September 10, 2015 sorry function createThumb($sourcefile, $target_file, $new_w, $new_h) { $root = $_SERVER['DOCUMENT_ROOT']."/"; $source_path = $sourcefile; // // Add file validation code here // list( $source_width, $source_height, $source_type ) = getimagesize( $source_path ); switch ( $source_type ) { case IMAGETYPE_GIF: $source_gdim = imagecreatefromgif( $source_path ); $ext = ".gif"; $fija = "imagegif"; break; case IMAGETYPE_JPEG: $source_gdim = imagecreatefromjpeg( $source_path ); $ext = ".jpg"; $fija = "imagejpeg"; break; case IMAGETYPE_PNG: $source_gdim = imagecreatefrompng( $source_path ); $ext = ".png"; $fija = "imagepng"; break; } $source_aspect_ratio = $source_width / $source_height; $desired_aspect_ratio = $new_w / $new_h; if ( $source_aspect_ratio > $desired_aspect_ratio ) { // // Triggered when source image is wider // $temp_height = $new_h; $temp_width = ( int ) ( $new_h * $source_aspect_ratio ); } else { // // Triggered otherwise (i.e. source image is similar or taller) // $temp_width = $new_w; $temp_height = ( int ) ( $new_w / $source_aspect_ratio ); } // // Resize the image into a temporary GD image // $temp_gdim = imagecreatetruecolor( $temp_width, $temp_height ); imagealphablending($temp_gdim, false); imagesavealpha($temp_gdim,true); $transparent = imagecolorallocatealpha($temp_gdim, 255, 255, 255, 127); imagefilledrectangle($temp_gdim, 0, 0, $temp_width,$temp_height, $transparent); imagecopyresampled( $temp_gdim, $source_gdim, 0, 0, 0, 0, $temp_width, $temp_height, $source_width, $source_height ); // // Copy cropped region from temporary image into the desired GD image // $x0 = ( $temp_width - $new_w ) / 2; $y0 = ( $temp_height - $new_h ) / 2; $desired_gdim = imagecreatetruecolor( $new_w, $new_h ); imagealphablending($desired_gdim, false); imagesavealpha($desired_gdim,true); $transparent = imagecolorallocatealpha($desired_gdim, 255, 255, 255, 127); imagefilledrectangle($desired_gdim, 0, 0, $new_w,$new_h, $transparent); imagecopy( $desired_gdim, $temp_gdim, 0, 0, $x0, $y0, $new_w, $new_h ); // // Render the image // Alternatively, you can save the image in file-system or database // if($fija($desired_gdim, $root.$target_file.$ext)) { imagedestroy($desired_gdim ); imagedestroy($temp_gdim); } return $ext; Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 10, 2015 Share Posted September 10, 2015 I have tested your function and I none of the images I used for re-sizing was rotated. How are you viewing the images? Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted September 10, 2015 Share Posted September 10, 2015 The image rotation issue, is usually to do with photos taken on a mobile device (iPhones are the main culprit). I'm sure there is a way to detect if the image is rotated, let me get back to you on it. Quote Link to comment Share on other sites More sharing options...
sopranolv Posted September 10, 2015 Author Share Posted September 10, 2015 The image rotation issue, is usually to do with photos taken on a mobile device (iPhones are the main culprit). I'm sure there is a way to detect if the image is rotated, let me get back to you on it. yes i think it is problem becouse i try image from google upload That's ok and when i try upload image taken by my samsung,it rotated how fix it someone know? Quote Link to comment Share on other sites More sharing options...
scootstah Posted September 10, 2015 Share Posted September 10, 2015 The EXIF data should contain an "Orientation" if the image is rotated. You can read this data and apply the necessary corrections. exif_read_data() 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.