Ejemplo 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;
}
Ejemplo n.º 2
0
 /**
  * nggAdmin::createThumbnail() - function to create or recreate a thumbnail
  * 
  * @class nggAdmin
  * @param object | int $image contain all information about the image or the id
  * @return string result code
  * @since v1.0.0
  */
 function create_thumbnail($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);
     // check for existing thumbnail
     if (file_exists($image->thumbPath)) {
         if (!is_writable($image->thumbPath)) {
             return $image->filename . __(' is not writeable ', 'nggallery');
         }
     }
     $thumb = new ngg_Thumbnail($image->imagePath, TRUE);
     // skip if file is not there
     if (!$thumb->error) {
         if ($ngg->options['thumbfix']) {
             // calculate correct ratio
             $wratio = $ngg->options['thumbwidth'] / $thumb->currentDimensions['width'];
             $hratio = $ngg->options['thumbheight'] / $thumb->currentDimensions['height'];
             if ($wratio > $hratio) {
                 // first resize to the wanted width
                 $thumb->resize($ngg->options['thumbwidth'], 0);
                 // 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 height
                 $thumb->resize(0, $ngg->options['thumbheight']);
                 // 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']);
         }
         // save the new thumbnail
         $thumb->save($image->thumbPath, $ngg->options['thumbquality']);
         nggAdmin::chmod($image->thumbPath);
         //read the new sizes
         $new_size = @getimagesize($image->thumbPath);
         $size['width'] = $new_size[0];
         $size['height'] = $new_size[1];
         // add them to the database
         nggdb::update_image_meta($image->pid, array('thumbnail' => $size));
     }
     $thumb->destruct();
     if (!empty($thumb->errmsg)) {
         return ' <strong>' . $image->filename . ' (Error : ' . $thumb->errmsg . ')</strong>';
     }
     // success
     return '1';
 }
Ejemplo 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;
}
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
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'];
            $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']);
        }
Ejemplo n.º 6
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>';
Ejemplo n.º 7
0
 /**
  * nggAdmin::createThumbnail() - function to create or recreate a thumbnail
  * 
  * @param object | int $image contain all information about the image or the id
  * @return string result code
  * @since v1.0.0
  */
 function create_thumbnail($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');
     }
     // check for existing thumbnail
     if (file_exists($image->thumbPath)) {
         if (!is_writable($image->thumbPath)) {
             return $image->filename . __(' is not writeable ', 'nggallery');
         }
     }
     $thumb = new ngg_Thumbnail($image->imagePath, TRUE);
     // skip if file is not there
     if (!$thumb->error) {
         if ($ngg->options['thumbcrop']) {
             // THX to Kees de Bruin, better thumbnails if portrait format
             $width = $ngg->options['thumbwidth'];
             $height = $ngg->options['thumbheight'];
             $curwidth = $thumb->currentDimensions['width'];
             $curheight = $thumb->currentDimensions['height'];
             if ($curwidth > $curheight) {
                 $aspect = 100 * $curwidth / $curheight;
             } else {
                 $aspect = 100 * $curheight / $curwidth;
             }
             $width = round($width * $aspect / 100);
             $height = round($height * $aspect / 100);
             $thumb->resize($width, $height);
             $thumb->cropFromCenter($width);
         } elseif ($ngg->options['thumbfix']) {
             // check for portrait format
             if ($thumb->currentDimensions['height'] > $thumb->currentDimensions['width']) {
                 $thumb->resize($ngg->options['thumbwidth'], 0);
                 // get optimal y startpos
                 $ypos = ($thumb->currentDimensions['height'] - $ngg->options['thumbheight']) / 2;
                 $thumb->crop(0, $ypos, $ngg->options['thumbwidth'], $ngg->options['thumbheight']);
             } else {
                 $thumb->resize(0, $ngg->options['thumbheight']);
                 // get optimal x startpos
                 $xpos = ($thumb->currentDimensions['width'] - $ngg->options['thumbwidth']) / 2;
                 $thumb->crop($xpos, 0, $ngg->options['thumbwidth'], $ngg->options['thumbheight']);
             }
         } else {
             $thumb->resize($ngg->options['thumbwidth'], $ngg->options['thumbheight']);
         }
         // save the new thumbnail
         $thumb->save($image->thumbPath, $ngg->options['thumbquality']);
         nggAdmin::chmod($image->thumbPath);
     }
     $thumb->destruct();
     if (!empty($thumb->errmsg)) {
         return ' <strong>' . $image->filename . ' (Error : ' . $thumb->errmsg . ')</strong>';
     }
     // success
     return '1';
 }