Esempio n. 1
0
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;
}
Esempio n. 2
0
 /**
  * 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';
 }
Esempio n. 3
0
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;
}
Esempio n. 4
0
**/
require_once dirname(dirname(__FILE__)) . '/ngg-config.php';
require_once NGGALLERY_ABSPATH . '/lib/image.php';
if (!is_user_logged_in()) {
    die(__('Cheatin&#8217; uh?'));
}
if (!current_user_can('NextGEN Manage gallery')) {
    die(__('Cheatin&#8217; 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 . '&amp;width=350&amp;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);
Esempio n. 5
0
 /**
  * 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;
 }
Esempio n. 6
0
<?php

// Load wp-config
require_once dirname(__FILE__) . '/ngg-config.php';
// reference thumbnail class
include_once nggGallery::graphic_library();
include_once 'lib/core.php';
// get the plugin options
$ngg_options = get_option('ngg_options');
// Some parameters from the URL
$pictureID = (int) $_GET['pid'];
$mode = isset($_GET['mode']) ? esc_attr($_GET['mode']) : '';
// let's get the image data
$picture = nggdb::find_image($pictureID);
$thumb = new ngg_Thumbnail($picture->imagePath);
// Resize if necessary
if (!empty($_GET['width']) || !empty($_GET['height'])) {
    // Sanitize
    $w = !empty($_GET['width']) ? intval($_GET['width']) : 0;
    $h = !empty($_GET['height']) ? intval($_GET['height']) : 0;
    // limit the maxium size, prevent server memory overload
    if ($w > 1280) {
        $w = 1280;
    }
    if ($h > 1280) {
        $h = 1280;
    }
    $thumb->resize($w, $h);
}
// Apply effects according to the mode parameter
if ($mode == 'watermark') {
Esempio n. 7
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;
 }
Esempio n. 8
0
include_once nggGallery::graphic_library();
include_once 'lib/core.php';
// get the plugin options
$ngg_options = get_option('ngg_options');
// Some parameters from the URL
if (!isset($_GET['pid'])) {
    exit;
}
$pictureID = (int) $_GET['pid'];
$mode = isset($_GET['mode']) ? $_GET['mode'] : '';
// let's get the image data
$picture = nggdb::find_image($pictureID);
if (!is_object($picture)) {
    exit;
}
$thumb = new ngg_Thumbnail($picture->imagePath);
// Resize if necessary
if (!empty($_GET['width']) || !empty($_GET['height'])) {
    // Sanitize
    $w = !empty($_GET['width']) ? intval($_GET['width']) : 0;
    $h = !empty($_GET['height']) ? intval($_GET['height']) : 0;
    // limit the maxium size, prevent server memory overload
    if ($w > 1920) {
        $w = 1920;
    }
    if ($h > 1280) {
        $h = 1280;
    }
    // Crop mode for post thumbnail
    if ($mode == 'crop') {
        // calculates the new dimentions for a downsampled image
Esempio n. 9
0
<?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>';
Esempio n. 10
0
 /**
  * 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';
 }
Esempio n. 11
0
<?php

// Load wp-config
require_once dirname(__FILE__) . '/ngg-config.php';
// reference thumbnail class
include_once nggGallery::graphic_library();
include_once 'lib/core.php';
// get the plugin options
$ngg_options = get_option('ngg_options');
// Some parameters from the URL
$pictureID = (int) $_GET['pid'];
$mode = attribute_escape($_GET['mode']);
// let's get the image data
$picture = nggdb::find_image($pictureID);
$thumb = new ngg_Thumbnail($picture->imagePath);
// Resize if necessary
if (!empty($_GET['width']) || !empty($_GET['height'])) {
    $thumb->resize(intval($_GET['width']), intval($_GET['height']));
}
// Apply effects according to the mode parameter
if ($mode == 'watermark') {
    if ($ngg_options['wmType'] == 'image') {
        $thumb->watermarkImgPath = $ngg_options['wmPath'];
        $thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']);
    } else {
        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']);
        }
    }