Exemplo n.º 1
0
<?php

// passes thru a image (with optional width & height specified)
namespace cd;

$name = File::getUploadPath($this->owner);
if (!empty($_GET['w']) && !empty($_GET['h'])) {
    $im = new ImageResizer($name);
    if ($_GET['w'] <= $im->getWidth() && $_GET['h'] <= $im->getHeight()) {
        $im->resizeAspect($_GET['w'], $_GET['h']);
    }
} else {
    $im = new Image($name);
}
$im->render();
Exemplo n.º 2
0
 /**
  * Helper function that imports a image file and shrinks it to max allowed dimensions
  */
 public static function importImage($type, &$key, $category = 0, $blind = false, $max_width = 800, $max_height = 800)
 {
     $error = ErrorHandler::getInstance();
     if (!file_exists($key['tmp_name'])) {
         throw new \Exception('file ' . $key['tmp_name'] . ' dont exist!');
     }
     $info = getimagesize($key['tmp_name']);
     switch ($info['mime']) {
         case 'image/jpeg':
             break;
         case 'image/png':
             break;
         case 'image/gif':
             break;
         default:
             $error->add('Uploaded file ' . $key['name'] . ' is not an image (mimetype ' . $info['mime'] . ')');
             return false;
     }
     $fileId = self::import($type, $key, $category, $blind);
     if (!$fileId) {
         return false;
     }
     $im = new ImageResizer(File::get($fileId));
     if ($im->width >= $max_width || $im->height >= $max_height) {
         $im->resizeAspect($max_width, $max_height);
         $im->render($im->mimetype, self::getUploadPath($fileId));
         self::sync($fileId);
         //updates tblFiles.size
     }
     return $fileId;
 }
Exemplo n.º 3
0
<?php

namespace cd;

set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../core/');
require_once 'core.php';
require_once 'ImageResizer.php';
$file = '/home/ml/Skrivbord/DSC_1853.JPG';
$x = new ImageResizer($file);
$x->resizeAspect(800, 800);
$x->render('gif', 'resized.gif');
echo "resized to " . $x->getWidth() . "x" . $x->getHeight() . "\n";