示例#1
0
function zesize_img($hinhanh)
{
    global $folder, $module, $module_config, $module_name;
    if ($hinhanh) {
        require_once NV_ROOTDIR . "/includes/class/image.class.php";
        $basename = basename($hinhanh);
        $image = new image($hinhanh, NV_MAX_WIDTH, NV_MAX_HEIGHT);
        // Creat new folder
        if (!file_exists(NV_UPLOADS_REAL_DIR . '/' . $module . "/" . $folder)) {
            nv_mkdir(NV_UPLOADS_REAL_DIR . '/' . $module, $folder);
        }
        $name = $basename;
        $i = 1;
        while (file_exists(NV_UPLOADS_REAL_DIR . '/' . $module . "/" . $folder . '/' . $name)) {
            $name = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename);
            $i++;
        }
        $image_info1 = $image->fileinfo;
        $img_w = $module_config[$module_name]['width'];
        $img_h = $module_config[$module_name]['height'];
        $image_info = array();
        $homeimg = "";
        if ($image_info1['width'] / $image_info1['height'] < $img_w / $img_h) {
            $image->resizeXY($img_w, NV_MAX_HEIGHT);
        } else {
            $image->resizeXY(NV_MAX_WIDTH, $img_h);
        }
        $image->cropFromLeft(0, 0, $img_w, $img_h);
        $image->save(NV_UPLOADS_REAL_DIR . '/' . $module . "/" . $folder, $name);
        $image_info = $image->create_Image_info;
        $homeimg = str_replace(NV_UPLOADS_REAL_DIR . '/' . $module . '/', '', $image_info['src']);
        $image->close();
    } else {
        $homeimg = "";
    }
    return $homeimg;
}
示例#2
0
 $array['avatar_height'] = intval($array['y2'] - $array['y1']);
 if (sizeof(array_filter(array($array['x1'], $array['y1'], $array['x2'], $array['y2'], $array['w'], $array['h']))) < 4 or $array['avatar_width'] < $global_config['avatar_width'] or $array['avatar_height'] < $global_config['avatar_height']) {
     $array['error'] = $lang_module['avata_error_data'];
 } else {
     $upload = new upload(array('images'), $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, NV_MAX_WIDTH, NV_MAX_HEIGHT);
     // Storage in temp dir
     $upload_info = $upload->save_file($_FILES['image_file'], NV_ROOTDIR . '/' . NV_TEMP_DIR, false);
     // Delete upload tmp
     @unlink($_FILES['image_file']['tmp_name']);
     if (empty($upload_info['error'])) {
         $basename = $upload_info['basename'];
         $basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . nv_genpass(8) . "_" . $user_info['userid'] . '\\2', $basename);
         $image = new image($upload_info['name'], NV_MAX_WIDTH, NV_MAX_HEIGHT);
         // Resize image, crop image
         $image->resizeXY($array['w'], $array['h']);
         $image->cropFromLeft($array['x1'], $array['y1'], $array['avatar_width'], $array['avatar_height']);
         $image->resizeXY($global_config['avatar_width'], $global_config['avatar_height']);
         // Save new image
         $image->save(NV_ROOTDIR . '/' . NV_TEMP_DIR, $basename);
         $image->close();
         if (file_exists($image->create_Image_info['src'])) {
             $array['success'] = true;
             $array['filename'] = str_replace(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/', '', $image->create_Image_info['src']);
         } else {
             $array['error'] = $lang_module['avata_error_save'];
         }
         @nv_deletefile($upload_info['name']);
     } else {
         $array['error'] = $upload_info['error'];
     }
 }
示例#3
0
}
$file = htmlspecialchars(trim($nv_Request->get_string('file', 'post,get')), ENT_QUOTES);
$file = basename($file);
if (empty($file) or !is_file(NV_ROOTDIR . '/' . $path . '/' . $file)) {
    die('ERROR#' . $lang_module['errorNotSelectFile'] . NV_ROOTDIR . '/' . $path . '/' . $file);
}
if ($nv_Request->isset_request('path', 'post') and $nv_Request->isset_request('x', 'post') and $nv_Request->isset_request('y', 'post')) {
    $config_logo = array();
    $config_logo['x'] = $nv_Request->get_int('x', 'post', 0);
    $config_logo['y'] = $nv_Request->get_int('y', 'post', 0);
    $config_logo['w'] = $nv_Request->get_int('w', 'post', 0);
    $config_logo['h'] = $nv_Request->get_int('h', 'post', 0);
    if ($config_logo['w'] > 0 and $config_logo['h'] > 0) {
        require_once NV_ROOTDIR . '/includes/class/image.class.php';
        $createImage = new image(NV_ROOTDIR . '/' . $path . '/' . $file, NV_MAX_WIDTH, NV_MAX_HEIGHT);
        $createImage->cropFromLeft($config_logo['x'], $config_logo['y'], $config_logo['w'], $config_logo['h']);
        $createImage->save(NV_ROOTDIR . '/' . $path, $file);
        $createImage->close();
        if (isset($array_dirname[$path])) {
            if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png)))$/i', $path . '/' . $file, $m)) {
                @nv_deletefile(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $m[1]);
            }
            $info = nv_getFileInfo($path, $file);
            $did = $array_dirname[$path];
            $db->query("UPDATE " . NV_UPLOAD_GLOBALTABLE . "_file SET filesize=" . $info['filesize'] . ", src='" . $info['src'] . "', srcwidth=" . $info['srcwidth'] . ", srcheight=" . $info['srcheight'] . ", sizes='" . $info['size'] . "', userid=" . $admin_info['userid'] . ", mtime=" . $info['mtime'] . " WHERE did = " . $did . " AND title = '" . $file . "'");
        }
        die('OK#' . basename($file));
    } else {
        die('ERROR#' . $lang_module['notlevel']);
    }
}