I have a little blackout with the simplest of the simplest.
I have a folder called "userpics" and in that folder there are 100x100 profile images named e.g. user-25.jpg. In that folder there also is a picture called user-none.jpg with a silhouette, used as a picture on a comments function when non-registered users posts a comment.
What I want to do is when a user is registered the user-none.jpg (with the silhouette) is copied and named e.g. user-26.jpg. The user can then later upload a new profile image from his account.
I just can't figure out how to copy the image. I tried this:
function CreateDummyProfileImage($user_id) {
$new_dummy = "images/userpics/user-".$user_id.".jpg";
$dummy = "images/userpics/user-none.jpg";
list($current_width, $current_height) = getimagesize($dummy);
$this->imageSizeH = 100;
$this->imageSizeW = 100;
$canvas = imagecreatetruecolor($this->imageSizeW, $this->imageSizeH);
$current_image = imagecreatefromjpeg($dummy);
imagecopy($canvas, $current_image, 0, 0, 0, 0, $current_width, $current_height);
imagejpeg($canvas, $new_dummy, 100);
}
But that doesn't seem to work.
SOLVED :
/**********************************************************
* Create a user with the basic info the user posted
* in the creation form.
*
* @param string | The name of the user
* @param string | The users email address
* @param string | The password to login with
**********************************************************/
function CreateUser($name, $email, $password) {
/***
* First we need no check if the email already exists in the system.
* The statement right below will do that
***/
$check_if_user_exists_sql = $this->db->selectSQL("email", "tdic_users", "email = '".$email."'");
$check_if_user_exists_result = $this->db->SQLquery($check_if_user_exists_sql);
if(mysql_num_rows($check_if_user_exists_result) > 0) {
$this->main->txtOutput("The user with email ". $email ." is already registered", "TXT_ERR"); //The email already exists in the system! No further processing from here!
} else {
/*** If the email couldn't be found we will create a new user ***/
/*** Array containing the fields required for user creation ***/
$fields = array(
"name" => $name,
"email" => $email,
"password" => $this->main->SaltMe(sha1($password)),
"user_date_created" => time(), //The current time
"user_last_logged_in" => 0,
"profileimage" => "user-none.jpg" //SET THIS INSTEAD OF COPYING THE AND RENAMING THE IMAGE
);
$create_user_sql = $this->db->insertSQL('tdic_users', $fields);
$create_user_result = $this->db->SQLquery($create_user_sql);
if($create_user_result) {
$this->ActivationMail($name, $email);
$this->main->txtOutput("You are now registered. In shorty you will recieve an email with an activation link. Please click that link to activate your account.", "TXT_OK"); //Everything went well - we will tell the user that!
} else {
$this->main->txtOutput("An error occured", "TXT_ERR"); //Whoops! Something went wrong! This is unexpected!
}
}
}