Beispiel #1
0
 /**
  * nggAdmin::resize_image() - create a new image, based on the height /width
  * 
  * @class nggAdmin
  * @param object | int $image contain all information about the image or the id
  * @param integer $width optional 
  * @param integer $height optional
  * @return string result code
  */
 function resize_image($image, $width = 0, $height = 0)
 {
     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 no parameter is set, take global settings
     $width = $width == 0 ? $ngg->options['imgWidth'] : $width;
     $height = $height == 0 ? $ngg->options['imgHeight'] : $height;
     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');
         }
         $file->resize($width, $height, 4);
         $file->save($image->imagePath, $ngg->options['imgQuality']);
         // read the new sizes
         $size = @getimagesize($image->imagePath);
         // add them to the database
         nggdb::update_image_meta($image->pid, array('width' => $size[0], 'height' => $size[1]));
         $file->destruct();
     } else {
         $file->destruct();
         return ' <strong>' . $image->filename . ' (Error : ' . $file->errmsg . ')</strong>';
     }
     return '1';
 }
Beispiel #2
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);
    } else {
Beispiel #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;
}
Beispiel #4
0
// 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') {
    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']);
        }
    }
} else {
    if ($mode == 'web20') {
Beispiel #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;
 }
Beispiel #6
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;
 }
Beispiel #7
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;
}
Beispiel #8
0
    // 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
        list($ratio_w, $ratio_h) = wp_constrain_dimensions($thumb->currentDimensions['width'], $thumb->currentDimensions['height'], $w, $h);
        // check ratio to decide which side should be resized
        $ratio_h < $h || $ratio_w == $w ? $thumb->resize(0, $h) : $thumb->resize($w, 0);
        // get the best start postion to crop from the middle
        $ypos = ($thumb->currentDimensions['height'] - $h) / 2;
        $thumb->crop(0, $ypos, $w, $h);
    } else {
        $thumb->resize($w, $h);
    }
}
// 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'];
Beispiel #9
0
 /**
  * nggAdmin::resize_image() - create a new image, based on the height /width
  * 
  * @param object | int $image contain all information about the image or the id
  * @param integer $width optional 
  * @param integer $height optional
  * @return string result code
  */
 function resize_image($image, $width = 0, $height = 0)
 {
     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 no parameter is set, take global settings
     $width = $width == 0 ? $ngg->options['imgWidth'] : $width;
     $height = $height == 0 ? $ngg->options['imgHeight'] : $height;
     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) {
         $file->resize($width, $height, 4);
         $file->save($image->imagePath, $ngg->options['imgQuality']);
         $file->destruct();
     } else {
         $file->destruct();
         return ' <strong>' . $image->filename . ' (Error : ' . $file->errmsg . ')</strong>';
     }
     return '1';
 }
Beispiel #10
0
// 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']);
        }
    }
} else {
    if ($mode == 'web20') {