Пример #1
0
function save_image_upload($upd_file, $key = '', $dir = 'temp', $whs = array(), $is_water = false, $need_return = false)
{
    require_once APP_ROOT_PATH . "system/utils/es_imagecls.php";
    $image = new es_imagecls();
    $image->max_size = intval(app_conf("MAX_IMAGE_SIZE"));
    $list = array();
    if (empty($key)) {
        foreach ($upd_file as $fkey => $file) {
            $list[$fkey] = false;
            $image->init($file, $dir);
            if ($image->save()) {
                $list[$fkey] = array();
                $list[$fkey]['url'] = $image->file['target'];
                $list[$fkey]['path'] = $image->file['local_target'];
                $list[$fkey]['name'] = $image->file['prefix'];
            } else {
                if ($image->error_code == -105) {
                    if ($need_return) {
                        return array('error' => 1, 'message' => '上传的图片太大');
                    } else {
                        echo "上传的图片太大";
                    }
                } elseif ($image->error_code == -104 || $image->error_code == -103 || $image->error_code == -102 || $image->error_code == -101) {
                    if ($need_return) {
                        return array('error' => 1, 'message' => '非法图像');
                    } else {
                        echo "非法图像";
                    }
                }
                exit;
            }
        }
    } else {
        $list[$key] = false;
        $image->init($upd_file[$key], $dir);
        if ($image->save()) {
            $list[$key] = array();
            $list[$key]['url'] = $image->file['target'];
            $list[$key]['path'] = $image->file['local_target'];
            $list[$key]['name'] = $image->file['prefix'];
        } else {
            if ($image->error_code == -105) {
                if ($need_return) {
                    return array('error' => 1, 'message' => '上传的图片太大');
                } else {
                    echo "上传的图片太大";
                }
            } elseif ($image->error_code == -104 || $image->error_code == -103 || $image->error_code == -102 || $image->error_code == -101) {
                if ($need_return) {
                    return array('error' => 1, 'message' => '非法图像');
                } else {
                    echo "非法图像";
                }
            }
            exit;
        }
    }
    $water_image = APP_ROOT_PATH . app_conf("WATER_MARK");
    $alpha = app_conf("WATER_ALPHA");
    $place = app_conf("WATER_POSITION");
    foreach ($list as $lkey => $item) {
        //循环生成规格图
        foreach ($whs as $tkey => $wh) {
            $list[$lkey]['thumb'][$tkey]['url'] = false;
            $list[$lkey]['thumb'][$tkey]['path'] = false;
            if ($wh[0] > 0 || $wh[1] > 0) {
                $thumb_type = isset($wh[2]) ? intval($wh[2]) : 0;
                //剪裁还是缩放, 0缩放 1剪裁
                if ($thumb = $image->thumb($item['path'], $wh[0], $wh[1], $thumb_type)) {
                    $list[$lkey]['thumb'][$tkey]['url'] = $thumb['url'];
                    $list[$lkey]['thumb'][$tkey]['path'] = $thumb['path'];
                    if (isset($wh[3]) && intval($wh[3]) > 0) {
                        $paths = pathinfo($list[$lkey]['thumb'][$tkey]['path']);
                        $path = $paths['dirname'];
                        $path = $path . "/origin/";
                        if (!is_dir($path)) {
                            @mkdir($path);
                            @chmod($path, 0777);
                        }
                        $filename = $paths['basename'];
                        @file_put_contents($path . $filename, @file_get_contents($list[$lkey]['thumb'][$tkey]['path']));
                        $image->water($list[$lkey]['thumb'][$tkey]['path'], $water_image, $alpha, $place);
                    }
                }
            }
        }
        if ($is_water) {
            $paths = pathinfo($item['path']);
            $path = $paths['dirname'];
            $path = $path . "/origin/";
            if (!is_dir($path)) {
                @mkdir($path);
                @chmod($path, 0777);
            }
            $filename = $paths['basename'];
            @file_put_contents($path . $filename, @file_get_contents($item['path']));
            $image->water($item['path'], $water_image, $alpha, $place);
        }
    }
    return $list;
}
Пример #2
0
 function saveimage($dir, $allow_water = true)
 {
     //image object
     require_once APP_ROOT_PATH . "system/utils/es_imagecls.php";
     $image = new es_imagecls();
     $image->max_size = intval(app_conf("MAX_IMAGE_SIZE"));
     $image->init($_FILES['file'], $dir);
     if ($image->save()) {
         $img_item['url'] = $image->file['target'];
         $img_item['path'] = $image->file['local_target'];
         $img_item['name'] = $image->file['prefix'];
         $img_item['width'] = $image->file['width'];
         $img_item['height'] = $image->file['height'];
     } else {
         if ($image->error_code == -105) {
             return array('error' => 1, 'message' => '上传的图片太大');
         } elseif ($image->error_code == -104 || $image->error_code == -103 || $image->error_code == -102 || $image->error_code == -101) {
             return array('error' => 1, 'message' => '非法图像');
         }
         exit;
     }
     //水印处理
     if ($allow_water && intval(app_conf("IS_WATER_MARK"))) {
         $is_water = intval(app_conf("IS_WATER_MARK"));
     }
     $water_image = APP_ROOT_PATH . app_conf("WATER_MARK");
     $alpha = intval(app_conf("WATER_ALPHA"));
     $place = intval(app_conf("WATER_POSITION"));
     if ($is_water) {
         $dirs = pathinfo($img_item['url']);
         $dir = $dirs['dirname'];
         $dir = $dir . "/origin/";
         $paths = pathinfo($img_item['path']);
         $path = $paths['dirname'];
         $path = $path . "/origin/";
         if (!is_dir($path)) {
             @mkdir($path);
             @chmod($path, 0777);
         }
         $filename = $paths['basename'];
         @file_put_contents($path . $filename, @file_get_contents($img_item['path']));
         $image->water($img_item['path'], $water_image, $alpha, $place);
         if ($GLOBALS['distribution_cfg']['OSS_TYPE'] && $GLOBALS['distribution_cfg']['OSS_TYPE'] != "NONE") {
             syn_to_remote_image_server($img_item['url']);
             //同步水印图
             syn_to_remote_image_server($dir . $filename);
             //同步原图
         }
     } else {
         if ($GLOBALS['distribution_cfg']['OSS_TYPE'] && $GLOBALS['distribution_cfg']['OSS_TYPE'] != "NONE") {
             syn_to_remote_image_server($img_item['url']);
         }
     }
     return $img_item;
 }