Exemplo 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;
}