Ejemplo n.º 1
0
        unset($files[$i]);
    }
}
// %End validate $dirpath
require $sjConfig['lib_dir'] . '/model/image.class.php';
$_RESULT['media'] = array();
$width = $_REQUEST['width'];
$height = $_REQUEST['height'];
$left = isset($_REQUEST['left']) ? $_REQUEST['left'] : 0;
$top = isset($_REQUEST['top']) ? $_REQUEST['top'] : 0;
$overrideOld = !empty($_REQUEST['override']);
$action = $_REQUEST['action'];
try {
    foreach ($files as $imagePath => $newName) {
        $file = $rootPath . $imagePath;
        $image = $fs->createImage($file, $overrideOld);
        $pathinfo = $fs->getPathInfo($file);
        switch ($action) {
            case 'resize':
                $image->resize($width, $height);
                break;
            case 'crop':
                $image->resize($width, $height, 'crop', array('x' => $left, 'y' => $top));
                break;
        }
        $image->save($pathinfo['dirname'] . '/' . $newName, 80);
        $_RESULT['media']['add'][] = str_replace($rootPath, '', $image->getSavedName());
        if ($overrideOld) {
            $_RESULT['media']['rm'][] = $imagePath;
        }
    }