Esempio n. 1
0
function resizer_route($route)
{
    if (!isset($route['params']['wildcard'])) {
        return false;
    }
    $config = ImageResizer::getConfig();
    $parts = explode('/', $route['params']['wildcard']);
    $params = array('w' => 'width', 'h' => 'height', 'q' => 'quality', 'cw' => 'crop_width', 'ch' => 'crop_height', 's' => 'scale', 'r' => 'rotation', 'xgr' => 'IMG_FILTER_GRAYSCALE', 'xbr' => 'brightness', 'xcn' => 'IMG_FILTER_CONTRAST', 'xco' => 'IMG_FILTER_COLORIZE', 'xed' => 'IMG_FILTER_EDGEDETECT', 'xem' => 'IMG_FILTER_EMBOSS', 'xgb' => 'IMG_FILTER_GAUSSIAN_BLUR', 'xsb' => 'IMG_FILTER_SELECTIVE_BLUR', 'xmr' => 'IMG_FILTER_MEAN_REMOVAL', 'xsm' => 'IMG_FILTER_SMOOTH', 'xpx' => 'IMG_FILTER_PIXELATE', 'cx' => 'cropx', 'cy' => 'cropy');
    $file = null;
    $options = array();
    for ($i = 0; $i < sizeof($parts); $i++) {
        $part = $parts[$i];
        if (is_array($file)) {
            $file[] = $part;
        } else {
            if ($part == 'bw') {
                $options['blackwhite'] = true;
            } else {
                if ($part == 'ratio') {
                    $options['ratio'] = true;
                } else {
                    if ($part == 'crop') {
                        $options['crop'] = true;
                    } else {
                        if (preg_match('/^([a-z]+)([0-9\\.]+)$/', $part, $matches)) {
                            if (isset($params[$matches[1]])) {
                                $options[$params[$matches[1]]] = $matches[2];
                            } else {
                                $options[$matches[1]] = $matches[2];
                            }
                        } else {
                            if ($part == 'f') {
                                $file = array();
                            } else {
                                if (isset($config['size'][$part])) {
                                    $options = array_merge($options, $config['size'][$part]);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (!is_array($file)) {
        return false;
    } else {
        $file = Gregory::absolutePath(implode('/', $file), array($config['path']));
    }
    if (!$file || empty($file)) {
        return false;
    }
    ini_set("memory_limit", $config['memory_limit']);
    $Resizer = new ImageResizer($file);
    $Resizer->resize($options);
    $Resizer->render();
    return true;
}
Esempio 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;
 }
<?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";