/** * Update watermark file */ function update_watermark($file) { if (empty($file)) { e(lang("no_watermark_found")); } else { $oldW = BASEDIR . "/images/photo_watermark.png"; if (file_exists($oldW)) { unset($oldW); } $info = getimagesize($file['tmp_name']); $width = $info[0]; $type = $info[2]; //pr($info,TRUE); if ($type == 3) { if (move_uploaded_file($file['tmp_name'], BASEDIR . "/images/photo_watermark.png")) { $wFile = BASEDIR . "/images/photo_watermark.png"; if ($width > $this->max_watermark_width) { /* Updating resizing code */ $img = new CB_Resizer($wFile); $img->target = $wFile; $img->_resize($this->max_watermark_width); $img->save(); //$this->createThumb( $wFile, $wFile, 'png', $this->max_watermark_width ); } } e(lang("watermark_updated"), "m"); } else { e(lang("upload_png_watermark")); } } }
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()) ); } }
function playlist_upload_cover($args) { global $db; $filename = $args['playlist_id']; $extension = GetExt($args['name']); $folder = create_dated_folder(PLAYLIST_COVERS_DIR); $uploaded_file = PLAYLIST_COVERS_DIR . '/' . $folder . '/' . $filename . '.' . $extension; if (!empty($filename)) { if (move_uploaded_file($args['tmp_name'], $uploaded_file)) { $cover_name = $filename . '.' . $extension; $resizer = new CB_Resizer($uploaded_file); $resizer->target = $uploaded_file; $resizer->resize(1280, 800); $resizer->save(); $db->update(tbl('playlists'), array('cover'), array($folder . '/' . $cover_name), " playlist_id = '" . $filename . "' "); return true; } } return false; }