Esempio n. 1
0
 /**
  * Image Resource ID for Watermark
  *
  * @var string
  *
  */
 function ngg_Thumbnail($fileName, $no_ErrorImage = false)
 {
     //make sure the GD library is installed
     if (!function_exists("gd_info")) {
         echo 'You do not have the GD Library installed.  This class requires the GD library to function properly.' . "\n";
         echo 'visit http://us2.php.net/manual/en/ref.image.php for more information';
         C_NextGEN_Bootstrap::shutdown();
     }
     //initialize variables
     $this->errmsg = '';
     $this->error = false;
     $this->currentDimensions = array();
     $this->newDimensions = array();
     $this->fileName = $fileName;
     $this->percent = 100;
     $this->maxWidth = 0;
     $this->maxHeight = 0;
     $this->watermarkImgPath = '';
     $this->watermarkText = '';
     //check to see if file exists
     if (!file_exists($this->fileName)) {
         $this->errmsg = 'File not found';
         $this->error = true;
     } elseif (!is_readable($this->fileName)) {
         $this->errmsg = 'File is not readable';
         $this->error = true;
     }
     //if there are no errors, determine the file format
     if ($this->error == false) {
         $data = @getimagesize($this->fileName);
         if (isset($data) && is_array($data)) {
             $extensions = array('1' => 'GIF', '2' => 'JPG', '3' => 'PNG');
             $extension = array_key_exists($data[2], $extensions) ? $extensions[$data[2]] : '';
             if ($extension) {
                 $this->format = $extension;
             } else {
                 $this->errmsg = 'Unknown file format';
                 $this->error = true;
             }
         } else {
             $this->errmsg = 'File is not an image';
             $this->error = true;
         }
     }
     // increase memory-limit if possible, GD needs this for large images
     // @ini_set('memory_limit', '128M');
     if ($this->error == false) {
         // Check memory consumption if file exists
         $this->checkMemoryForImage($this->fileName);
     }
     //initialize resources if no errors
     if ($this->error == false) {
         switch ($this->format) {
             case 'GIF':
                 $this->oldImage = ImageCreateFromGif($this->fileName);
                 break;
             case 'JPG':
                 $this->oldImage = ImageCreateFromJpeg($this->fileName);
                 break;
             case 'PNG':
                 $this->oldImage = ImageCreateFromPng($this->fileName);
                 break;
         }
         if (!$this->oldImage) {
             $this->errmsg = 'Create Image failed. Check memory limit';
             $this->error = true;
         } else {
             $size = GetImageSize($this->fileName);
             $this->currentDimensions = array('width' => $size[0], 'height' => $size[1]);
             $this->newImage = $this->oldImage;
         }
     }
     if ($this->error == true) {
         if (!$no_ErrorImage) {
             $this->showErrorImage();
         }
         return;
     }
 }
Esempio n. 2
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');
    }
    $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);
    $crop_frame = array('x' => $x, 'y' => $y, 'width' => $w, 'height' => $h);
    $registry = C_Component_Registry::get_instance();
    $storage = C_Gallery_Storage::get_instance();
    // XXX NextGEN Legacy wasn't handling watermarks or reflections at this stage, so we're forcefully disabling them to maintain compatibility
    $params = array('watermark' => false, 'reflection' => false, 'crop' => true, 'crop_frame' => $crop_frame);
    $result = $storage->generate_thumbnail($id, $params);
    if ($result) {
        echo "OK";
    } else {
        header('HTTP/1.1 500 Internal Server Error');
        echo "KO";
    }
    C_NextGEN_Bootstrap::shutdown();
}
Esempio n. 3
0
 /**
  * Checks the 'callback' parameter for possible ajax-like actions to take
  *
  * @param $wp
  */
 function check_request($wp)
 {
     $app = C_Component_Registry::get_instance()->get_utility('I_Router')->get_routed_app();
     if (!$app->get_parameter('callback')) {
         return;
     }
     switch ($app->get_parameter('callback')) {
         case 'imagerotator':
             require_once dirname(__FILE__) . '/xml/imagerotator.php';
             break;
         case 'json':
             require_once dirname(__FILE__) . '/xml/json.php';
             break;
         case 'image':
             require_once dirname(__FILE__) . '/nggshow.php';
             break;
         default:
             return;
     }
     C_NextGEN_Bootstrap::shutdown();
 }
 /**
  * Executes an action of a particular controller
  * @param array $handler
  */
 function execute_route_handler($handler)
 {
     // Get action
     $action = $handler['action'];
     // Get controller
     $controller = $this->object->get_registry()->get_utility($handler['controller'], $handler['context']);
     // Call action
     $controller->{$action}();
     // Clean Exit (fastcgi safe)
     C_NextGEN_Bootstrap::shutdown();
 }
Esempio n. 5
0
        // 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']);
        }
    }
} else {
    if ($mode == 'web20') {
        $thumb->createReflection(40, 40, 50, false, '#a4a4a4');
    }
}
// Show thumbnail
$thumb->show();
$thumb->destruct();
C_NextGEN_Bootstrap::shutdown();