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()) ); } }
/** * This function inserts EXIF data embedded by cameras. * * @global OBJECT $db * @global OBJECT $cbphoto * @param ARRAY $photo * @return INT */ function insert_exif_data($photo) { global $db, $cbphoto; if (!is_array($photo)) { $ph = $cbphoto->get_photo($photo); } else { $ph = $photo; } if (is_array($ph) && isset($ph['photo_id'])) { $dir = PHOTOS_DIR . '/' . get_photo_date_folder($ph) . '/'; if (strtolower($ph['ext']) != 'jpg') { /* return if photo is not jpg */ return; } $file = get_original_photo($ph); $path = $dir . $file; if (file_exists($path)) { /* File exists. read the exif data. Thanks to CopperMine, Love you */ $data = read_exif_data_raw($path, 0); if (isset($data['SubIFD'])) { $exif_to_include = array('IFD0', 'SubIFD', 'IFD1', 'InteroperabilityIFD'); foreach ($exif_to_include as $eti) { if (isset($data[$eti])) { $exif[$eti] = $data[$eti]; } } /* Removing unknown tags from exif data */ foreach ($exif as $parent => $tags) { foreach ($tags as $tag => $value) { if ($tag == 'MakerNote') { if (is_array($value)) { foreach ($value as $mtag => $mvalue) { if (strpos($mtag, 'unknown') !== false) { unset($exif[$parent][$tag][$mtag]); } else { $exif[$parent][$tag][$mtag] = trim($mvalue); } } } } if (is_array($value)) { continue; } if (strpos($tag, 'unknown') !== false) { unset($exif[$parent][$tag]); } else { $exif[$parent][$tag] = trim($value); } } } $jexif = json_encode($exif); $jexif = preg_replace('/\\\\(u000)(.){1}/', '', $jexif); /* add new meta of exif_data for current photo */ $insert_id = $db->insert(tbl('photosmeta'), array('photo_id', 'meta_name', 'meta_value'), array($ph['photo_id'], 'exif_data', "|no_mc|{$jexif}")); if ($insert_id) { /* update photo has_exif to yes, so we know that this photo has exif data */ $db->update(tbl($cbphoto->p_tbl), array('has_exif'), array('yes'), " photo_id = '" . $ph['photo_id'] . "' "); return $insert_id; } } } } }