/** * 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'; }
die(__('Cheatin’ uh?')); } if (!current_user_can('NextGEN Manage gallery')) { die(__('Cheatin’ uh?')); } global $wpdb; $id = (int) $_GET['id']; // let's get the image data $picture = nggdb::find_image($id); include_once nggGallery::graphic_library(); $ngg_options = get_option('ngg_options'); $thumb = new ngg_Thumbnail($picture->imagePath, TRUE); $thumb->resize(350, 350); // we need the new dimension $resizedPreviewInfo = $thumb->newDimensions; $thumb->destruct(); $preview_image = NGGALLERY_URLPATH . 'nggshow.php?pid=' . $picture->pid . '&width=350&height=350'; $imageInfo = @getimagesize($picture->imagePath); $rr = round($imageInfo[0] / $resizedPreviewInfo['newWidth'], 2); if ($ngg_options['thumbfix'] == 1) { $WidthHtmlPrev = $ngg_options['thumbwidth']; $HeightHtmlPrev = $ngg_options['thumbheight']; } else { // H > W if ($imageInfo[1] > $imageInfo[0]) { $HeightHtmlPrev = $ngg_options['thumbheight']; $WidthHtmlPrev = round($imageInfo[0] / ($imageInfo[1] / $ngg_options['thumbheight']), 0); } else { $WidthHtmlPrev = $ngg_options['thumbwidth']; $HeightHtmlPrev = round($imageInfo[1] / ($imageInfo[0] / $ngg_options['thumbwidth']), 0); }
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; }
/** * 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; }
/** * 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'; }