function createNewThumb() { global $ngg; // check for correct capability if (!is_user_logged_in()) { die('-1'); } // check for correct NextGEN capability if (!current_user_can('NextGEN Manage gallery')) { die('-1'); } include_once nggGallery::graphic_library(); $id = (int) $_POST['id']; $picture = nggdb::find_image($id); $x = round($_POST['x'] * $_POST['rr'], 0); $y = round($_POST['y'] * $_POST['rr'], 0); $w = round($_POST['w'] * $_POST['rr'], 0); $h = round($_POST['h'] * $_POST['rr'], 0); $thumb = new ngg_Thumbnail($picture->imagePath, TRUE); $thumb->crop($x, $y, $w, $h); // Note : the routine is a bit different to create_thumbnail(), due to rounding it's resized in the other way if ($ngg->options['thumbfix']) { // check for portrait format if ($thumb->currentDimensions['height'] > $thumb->currentDimensions['width']) { // first resize to the wanted height, here changed to create_thumbnail() $thumb->resize(0, $ngg->options['thumbheight']); // get optimal y startpos $ypos = ($thumb->currentDimensions['height'] - $ngg->options['thumbheight']) / 2; $thumb->crop(0, $ypos, $ngg->options['thumbwidth'], $ngg->options['thumbheight']); } else { // first resize to the wanted width, here changed to create_thumbnail() $thumb->resize($ngg->options['thumbwidth'], 0); // // get optimal x startpos $xpos = ($thumb->currentDimensions['width'] - $ngg->options['thumbwidth']) / 2; $thumb->crop($xpos, 0, $ngg->options['thumbwidth'], $ngg->options['thumbheight']); } //this create a thumbnail but keep ratio settings } else { $thumb->resize($ngg->options['thumbwidth'], $ngg->options['thumbheight']); } if ($thumb->save($picture->thumbPath, 100)) { //read the new sizes $new_size = @getimagesize($picture->thumbPath); $size['width'] = $new_size[0]; $size['height'] = $new_size[1]; // add them to the database nggdb::update_image_meta($picture->pid, array('thumbnail' => $size)); echo "OK"; } else { header('HTTP/1.1 500 Internal Server Error'); echo "KO"; } exit; }
/** * nggAdmin::set_watermark() - set the watermark for the image * * @class nggAdmin * @param object | int $image contain all information about the image or the id * @return string result code */ function set_watermark($image) { global $ngg; if (!class_exists('ngg_Thumbnail')) { require_once nggGallery::graphic_library(); } if (is_numeric($image)) { $image = nggdb::find_image($image); } if (!is_object($image)) { return __('Object didn\'t contain correct data', 'nggallery'); } // before we start we import the meta data to database (required for uploads before V1.4.0) nggAdmin::maybe_import_meta($image->pid); if (!is_writable($image->imagePath)) { return ' <strong>' . $image->filename . __(' is not writeable', 'nggallery') . '</strong>'; } $file = new ngg_Thumbnail($image->imagePath, TRUE); // skip if file is not there if (!$file->error) { // If required save a backup copy of the file if ($ngg->options['imgBackup'] == 1 && !file_exists($image->imagePath . '_backup')) { @copy($image->imagePath, $image->imagePath . '_backup'); } if ($ngg->options['wmType'] == 'image') { $file->watermarkImgPath = $ngg->options['wmPath']; $file->watermarkImage($ngg->options['wmPos'], $ngg->options['wmXpos'], $ngg->options['wmYpos']); } if ($ngg->options['wmType'] == 'text') { $file->watermarkText = $ngg->options['wmText']; $file->watermarkCreateText($ngg->options['wmColor'], $ngg->options['wmFont'], $ngg->options['wmSize'], $ngg->options['wmOpaque']); $file->watermarkImage($ngg->options['wmPos'], $ngg->options['wmXpos'], $ngg->options['wmYpos']); } $file->save($image->imagePath, $ngg->options['imgQuality']); } $file->destruct(); if (!empty($file->errmsg)) { return ' <strong>' . $image->filename . ' (Error : ' . $file->errmsg . ')</strong>'; } return '1'; }
/** * This function creates a cache for all singlepics to reduce the CPU load * * @param int $width * @param int $height * @param string $mode could be watermark | web20 | crop * @return the url for the image or false if failed */ function cached_singlepic_file($width = '', $height = '', $mode = '') { $ngg_options = get_option('ngg_options'); include_once nggGallery::graphic_library(); // cache filename should be unique $cachename = $this->pid . '_' . $mode . '_' . $width . 'x' . $height . '_' . $this->filename; $cachefolder = WINABSPATH . $ngg_options['gallerypath'] . 'cache/'; $cached_url = site_url() . '/' . $ngg_options['gallerypath'] . 'cache/' . $cachename; $cached_file = $cachefolder . $cachename; // check first for the file if (file_exists($cached_file)) { return $cached_url; } // create folder if needed if (!file_exists($cachefolder)) { if (!wp_mkdir_p($cachefolder)) { return false; } } $thumb = new ngg_Thumbnail($this->imagePath, TRUE); // echo $thumb->errmsg; if (!$thumb->error) { if ($mode == 'crop') { // calculates the new dimentions for a downsampled image list($ratio_w, $ratio_h) = wp_constrain_dimensions($thumb->currentDimensions['width'], $thumb->currentDimensions['height'], $width, $height); // check ratio to decide which side should be resized $ratio_h < $height || $ratio_w == $width ? $thumb->resize(0, $height) : $thumb->resize($width, 0); // get the best start postion to crop from the middle $ypos = ($thumb->currentDimensions['height'] - $height) / 2; $thumb->crop(0, $ypos, $width, $height); } else { $thumb->resize($width, $height); } if ($mode == 'watermark') { if ($ngg_options['wmType'] == 'image') { $thumb->watermarkImgPath = $ngg_options['wmPath']; $thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']); } if ($ngg_options['wmType'] == 'text') { $thumb->watermarkText = $ngg_options['wmText']; $thumb->watermarkCreateText($ngg_options['wmColor'], $ngg_options['wmFont'], $ngg_options['wmSize'], $ngg_options['wmOpaque']); $thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']); } } if ($mode == 'web20') { $thumb->createReflection(40, 40, 50, false, '#a4a4a4'); } // save the new cache picture $thumb->save($cached_file, $ngg_options['imgQuality']); } $thumb->destruct(); // check again for the file if (file_exists($cached_file)) { return $cached_url; } return false; }
function cached_singlepic_file($width = '', $height = '', $mode = '') { // This function creates a cache for all singlepics to reduce the CPU load $ngg_options = get_option('ngg_options'); include_once nggGallery::graphic_library(); // cache filename should be unique $cachename = $this->pid . '_' . $mode . '_' . $width . 'x' . $height . '_' . $this->filename; $cachefolder = WINABSPATH . $ngg_options['gallerypath'] . 'cache/'; $cached_url = get_option('siteurl') . '/' . $ngg_options['gallerypath'] . 'cache/' . $cachename; $cached_file = $cachefolder . $cachename; // check first for the file if (file_exists($cached_file)) { return $cached_url; } // create folder if needed if (!file_exists($cachefolder)) { if (!wp_mkdir_p($cachefolder)) { return false; } } $thumb = new ngg_Thumbnail($this->imagePath, TRUE); // echo $thumb->errmsg; if (!$thumb->error) { $thumb->resize($width, $height); if ($mode == 'watermark') { if ($ngg_options['wmType'] == 'image') { $thumb->watermarkImgPath = $ngg_options['wmPath']; $thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']); } if ($ngg_options['wmType'] == 'text') { $thumb->watermarkText = $ngg_options['wmText']; $thumb->watermarkCreateText($ngg_options['wmColor'], $ngg_options['wmFont'], $ngg_options['wmSize'], $ngg_options['wmOpaque']); $thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']); } } if ($mode == 'web20') { $thumb->createReflection(40, 40, 50, false, '#a4a4a4'); } // save the new cache picture $thumb->save($cached_file, $ngg_options['imgQuality']); } $thumb->destruct(); // check again for the file if (file_exists($cached_file)) { return $cached_url; } return false; }
function createNewThumb() { // check for correct capability if (!is_user_logged_in()) { die('-1'); } // check for correct NextGEN capability if (!current_user_can('NextGEN Manage gallery')) { die('-1'); } require_once dirname(dirname(__FILE__)) . '/ngg-config.php'; include_once nggGallery::graphic_library(); $ngg_options = get_option('ngg_options'); $id = (int) $_POST['id']; $picture = nggdb::find_image($id); $x = round($_POST['x'] * $_POST['rr'], 0); $y = round($_POST['y'] * $_POST['rr'], 0); $w = round($_POST['w'] * $_POST['rr'], 0); $h = round($_POST['h'] * $_POST['rr'], 0); $thumb = new ngg_Thumbnail($picture->imagePath, TRUE); $thumb->crop($x, $y, $w, $h); if ($ngg_options['thumbfix']) { if ($thumb->currentDimensions['height'] > $thumb->currentDimensions['width']) { $thumb->resize($ngg_options['thumbwidth'], 0); } else { $thumb->resize(0, $ngg_options['thumbheight']); } } else { $thumb->resize($ngg_options['thumbwidth'], $ngg_options['thumbheight'], $ngg_options['thumbResampleMode']); } if ($thumb->save($picture->thumbPath, 100)) { //read the new sizes $new_size = @getimagesize($picture->thumbPath); $size['width'] = $new_size[0]; $size['height'] = $new_size[1]; // add them to the database nggdb::update_image_meta($picture->pid, array('thumbnail' => $size)); echo "OK"; } else { header('HTTP/1.1 500 Internal Server Error'); echo "KO"; } exit; }
<?php require_once '../config.php'; require_once nggGallery::graphic_library(); // Pull the image from the NextGen DB $pictureID = $_REQUEST['pictureID']; $pic = nggdb::find_image($pictureID); // If Processing the Crop if (!empty($_POST['ngg_crop'])) { $image = new ngg_Thumbnail($pic->imagePath, TRUE); // Create backup @copy($image->fileName, $image->fileName . '_backup'); $image->crop($_POST['ngg_crop']['x1'], $_POST['ngg_crop']['y1'], $_POST['ngg_crop']['cropwidth'], $_POST['ngg_crop']['cropheight']); $image->save($image->fileName); // Save the new MetaData nggdb::update_image_meta($pictureID, array('width' => $_POST['ngg_crop']['cropwidth'], 'height' => $_POST['ngg_crop']['cropheight'])); exit; } echo '<div class="ngg_crop">'; echo '<form class="ngg_crop_form" action="' . $nggcropobj->plugin_path . 'ajax/imagecrop.php" method="post">'; echo '<input type="hidden" id="pictureID" name="pictureID" value="' . $pictureID . '">'; echo '<input type="hidden" id="cropprocess" name="ngg_crop[cropprocess]" value="1">'; echo '<input type="hidden" id="x1" name="ngg_crop[x1]" />'; echo '<input type="hidden" id="y1" name="ngg_crop[y1]" />'; echo '<input type="hidden" id="x2" name="ngg_crop[x2]" />'; echo '<input type="hidden" id="y2" name="ngg_crop[y2]" />'; echo '<table cellspacing="3">'; echo '<tr>'; echo '<td class="ngg_crop_image">'; echo '<img src="' . $pic->imageURL . '?' . rand(0, 10000) . '" id="cropthis" style="display: none">'; echo '</td>';
/** * nggAdmin::set_watermark() - set the watermarl for the image * * @param object | int $image contain all information about the image or the id * @return string result code */ function set_watermark($image) { global $ngg; if (!class_exists('ngg_Thumbnail')) { require_once nggGallery::graphic_library(); } if (is_numeric($image)) { $image = nggdb::find_image($image); } if (!is_object($image)) { return __('Object didn\'t contain correct data', 'nggallery'); } if (!is_writable($image->imagePath)) { return ' <strong>' . $image->filename . __(' is not writeable', 'nggallery') . '</strong>'; } $file = new ngg_Thumbnail($image->imagePath, TRUE); // skip if file is not there if (!$file->error) { if ($ngg->options['wmType'] == 'image') { $file->watermarkImgPath = $ngg->options['wmPath']; $file->watermarkImage($ngg->options['wmPos'], $ngg->options['wmXpos'], $ngg->options['wmYpos']); } if ($ngg->options['wmType'] == 'text') { $file->watermarkText = $ngg->options['wmText']; $file->watermarkCreateText($ngg->options['wmColor'], $ngg->options['wmFont'], $ngg->options['wmSize'], $ngg->options['wmOpaque']); $file->watermarkImage($ngg->options['wmPos'], $ngg->options['wmXpos'], $ngg->options['wmYpos']); } $file->save($image->imagePath, $ngg->options['imgQuality']); } $file->destruct(); if (!empty($file->errmsg)) { return ' <strong>' . $image->filename . ' (Error : ' . $file->errmsg . ')</strong>'; } return '1'; }