Jump to content

avatar upload sizes


sopranolv

Recommended Posts

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 ?

Link to comment
Share on other sites

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;
}
Link to comment
Share on other sites

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;
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.