Beispiel #1
0
function make_new_avatar($array = null)
{
    global $cbphoto, $userquery, $photo, $db, $cbcollection;
    if (is_null($array)) {
        $array = $_POST;
    }
    /* include resizer class */
    include_once 'includes/classes/resizer.class.php';
    $date_dir = get_photo_date_folder($photo);
    /* get original photo */
    $p = get_original_photo($photo);
    /* define source and decode photo details */
    $source = PHOTOS_DIR . '/' . $date_dir . '/' . $p;
    $pd = json_decode($photo['photo_details'], true);
    /* coordinates */
    $x = mysql_clean($array['start_x']);
    $x2 = mysql_clean($array['end_x']);
    $y = mysql_clean($array['start_y']);
    $y2 = mysql_clean($array['end_y']);
    if (!is_numeric($x) || !is_numeric($x2) || !is_numeric($y) || !is_numeric($y2)) {
        e('Unable to crop. Coordinates were unrealiable.');
    } else {
        /*
         * We will be using the original photo to crop the avatar.
         * First we'll covert the posted pixels to percentage
         * Second get pixels from original photo using percentage
         * Using newly computed pixels crop from original photo
         * Save it in avatar collection, make it source and start making avatars
         */
        $xx = $x / $pd['l']['width'] * 100;
        // compute percentage
        $xx2 = $x2 / $pd['l']['width'] * 100;
        // compute percentage
        $newX = $xx * $pd['o']['width'] / 100;
        // compute pixels
        $newX2 = $xx2 * $pd['o']['width'] / 100;
        // compute pixels
        $yy = $y / $pd['l']['height'] * 100;
        // compute percentage
        $yy2 = $y2 / $pd['l']['height'] * 100;
        // compute percentage
        $newY = $yy * $pd['o']['height'] / 100;
        // compute pixels
        $newY2 = $yy2 * $pd['o']['height'] / 100;
        // compute pixels
        /* set source */
        $r = new CB_Resizer($source);
        $filename = cb_filename();
        $photopath = PHOTOS_DIR . '/' . createDataFolders(PHOTOS_DIR);
        $avatar_dir = USER_THUMBS_DIR . '/';
        $uid = $userquery->udetails['userid'];
        $ext = $photo['ext'];
        $cid = cb_create_user_avatar_collection($userquery->udetails);
        /* Save the cropped as original source of photo. */
        $new_photo = $r->target = $photopath . '/' . $filename . "." . $photo['ext'];
        $r->_crop($newX, $newY, $newX2, $newY2);
        $r->save();
        $fields = array('photo_title' => 'Avatar', 'photo_description' => ' ', 'photo_tags' => ' ', 'filename' => $filename, 'userid' => $uid, 'ext' => $photo['ext'], 'is_avatar' => true, 'collection_id' => $cid);
        /* Inserting photo in user's avatar collection */
        $photo_id = $cbphoto->insert_photo($fields);
        $avatar = $uid . '_' . $filename . '.' . $ext;
        $avatarpath = $avatar_dir . $avatar;
        /* Make $new_photo the source */
        $r->source = $r->target;
        /* Big Thumb */
        $r->target = $avatarpath;
        $r->_resize(AVATAR_SIZE, AVATAR_SIZE);
        $r->save();
        /* Small Thumb */
        $r->target = USER_THUMBS_DIR . '/' . $uid . '_' . $filename . '-small.' . $photo['ext'];
        $r->_resize(AVATAR_SMALL_SIZE, AVATAR_SMALL_SIZE);
        $r->save();
        /* Update user avatar field */
        $db->update(tbl('users'), array('avatar'), array($avatar), " userid = '" . $uid . "' ");
        /* Update cover photo of collection */
        $cbcollection->set_cover_photo($photo_id, $cid);
        /* go back to photo */
        redirect_to($cbphoto->photo_links($photo, 'view_photo'));
        /* go to user profile */
        //redirect_to( $userquery->profile_link(userid()) );
    }
}
Beispiel #2
0
     $cbphoto->generate_photos($photo_id);
     if (!error()) {
         $image_url = get_image_url($photo_id, 'l');
         echo json_encode(array('success' => true, 'photo_id' => $photo_id, 'photo_preview' => $image_url));
     } else {
         echo json_encode(array('error' => error()));
     }
     break;
 case "insert_photo":
     /* $_POST['photo_title'] = genTags(str_replace(array('_','-'),' ',$_POST['photo_title']));
     		$_POST['photo_description'] = genTags(str_replace(array('_','-'),' ',$_POST['photo_description']));
     		$_POST['photo_tags'] = genTags(str_replace(array(' ','_','-'),', ',$_POST['photo_tags']));
     		$_POST['server_url'] = mysql_clean($_POST['server_url']);
     		$_POST['folder'] = str_replace('..','',mysql_clean($_POST['folder'])); */
     $name = mysql_clean($_POST['title']);
     $filename = cb_filename();
     $extension = GetExt($name);
     $name = str_replace('.' . $extension, '', $name);
     $photo_dir = createDataFolders(PHOTOS_DIR);
     $post_data = array('photo_title' => $name, 'photo_description' => $name, 'photo_tags' => genTags(str_replace(array(' ', '_', '-'), ', ', $name)), 'filename' => $filename, 'folder' => $photo_dir, 'collection_id' => mysql_clean($_POST['collection']), 'ext' => $extension);
     $insert_id = $cbphoto->insert_photo($post_data);
     if (error()) {
         $response['error'] = error();
     }
     if (msg()) {
         $response['success'] = true;
         $response['id'] = $insert_id;
         $response['file'] = $filename;
         $response['extension'] = $extension;
         $response['file_directory'] = $photo_dir;
     }