Exemplo n.º 1
0
if ($action == 'crop') {
    $x1 = isset($_POST['x1']) ? intval($_POST['x1']) : 0;
    $y1 = isset($_POST['y1']) ? intval($_POST['y1']) : 140;
    $width = isset($_POST['width']) ? intval($_POST['width']) : 960;
    $height = isset($_POST['height']) ? intval($_POST['height']) : 134;
    $top_img = isset($_POST['img']) ? $_POST['img'] : '';
    $time = time();
    //create topimg
    $topimg_path = Option::UPLOADFILE_PATH . gmdate('Ym') . '/top-' . $time . '.jpg';
    $ret = imageCropAndResize($top_img, $topimg_path, 0, 0, $x1, $y1, $width, $height, $width, $height);
    if (false === $ret) {
        emDirect("./template.php?action=custom-top&error_a=1");
    }
    //create mini topimg
    $topimg_mini_path = Option::UPLOADFILE_PATH . gmdate('Ym') . '/top-' . $time . '_mini.jpg';
    $ret = imageCropAndResize($topimg_path, $topimg_mini_path, 0, 0, 0, 0, 230, 48, $width, $height);
    if (false === $ret) {
        emDirect("./template.php?action=custom-top&error_a=1");
    }
    @unlink($top_img);
    $custom_topimgs = Option::get('custom_topimgs');
    array_push($custom_topimgs, substr($topimg_path, 3));
    Option::updateOption('topimg', substr($topimg_path, 3));
    Option::updateOption('custom_topimgs', serialize($custom_topimgs));
    $CACHE->updateCache('options');
    emDirect("./template.php?action=custom-top&activated=1");
}
//安装模板
if ($action == 'install') {
    include View::getView('header');
    require_once View::getView('template_install');
Exemplo n.º 2
0
/**
 * 图片生成缩略图
 *
 * @param string $img 预缩略的图片
 * @param string $thum_path 生成缩略图路径
 * @param int $max_w 缩略图最大宽度 px
 * @param int $max_h 缩略图最大高度 px
 * @return unknown
 */
function resizeImage($img, $thum_path, $max_w, $max_h)
{
    if (!in_array(getFileSuffix($thum_path), array('jpg', 'png', 'jpeg', 'gif'))) {
        return false;
    }
    if (!function_exists('ImageCreate')) {
        return false;
    }
    $size = chImageSize($img, $max_w, $max_h);
    $newwidth = $size['w'];
    $newheight = $size['h'];
    $w = $size['rc_w'];
    $h = $size['rc_h'];
    if ($w <= $max_w && $h <= $max_h) {
        return false;
    }
    return imageCropAndResize($img, $thum_path, 0, 0, 0, 0, $newwidth, $newheight, $w, $h);
}