Пример #1
0
function get_spec_image($img_path, $width = 0, $height = 0, $gen = 0, $is_preview = true, $is_deleteable = true)
{
    if ($width == 0) {
        $new_path = $img_path;
    } else {
        $img_name = substr($img_path, 0, -4);
        $img_ext = substr($img_path, -3);
        if ($is_deleteable) {
            if ($is_preview) {
                $new_path = $img_name . "_" . $width . "x" . $height . ".jpg";
            } else {
                $new_path = $img_name . "o_" . $width . "x" . $height . ".jpg";
            }
        } else {
            if ($is_preview) {
                $new_path = $img_name . "" . $width . "" . $height . ".jpg";
            } else {
                $new_path = $img_name . "o" . $width . "" . $height . ".jpg";
            }
        }
        if (!file_exists(APP_ROOT_PATH . $new_path)) {
            require_once APP_ROOT_PATH . "system/utils/es_imagecls.php";
            $imagec = new es_imagecls();
            $thumb = $imagec->thumb(APP_ROOT_PATH . $img_path, $width, $height, $gen, true, "", $is_preview, $is_deleteable);
            if (app_conf("PUBLIC_DOMAIN_ROOT") != '') {
                $paths = pathinfo($new_path);
                $path = str_replace("./", "", $paths['dirname']);
                $filename = $paths['basename'];
                $pathwithoupublic = str_replace("public/", "", $path);
                $syn_url = app_conf("PUBLIC_DOMAIN_ROOT") . "/es_file.php?username="******"IMAGE_USERNAME") . "&password="******"IMAGE_PASSWORD") . "&file=" . get_domain() . APP_ROOT . "/" . $path . "/" . $filename . "&path=" . $pathwithoupublic . "/&name=" . $filename . "&act=0";
                @file_get_contents($syn_url);
            }
        }
    }
    return $new_path;
}
Пример #2
0
function get_spec_image($img_path, $width = 0, $height = 0, $gen = 0, $is_preview = true, $is_deleteable = true)
{
    //关于ALIOSS的生成
    if ($GLOBALS['distribution_cfg']['OSS_TYPE'] && $GLOBALS['distribution_cfg']['OSS_TYPE'] == "ALI_OSS") {
        $pathinfo = pathinfo($img_path);
        $file = $pathinfo['basename'];
        $dir = $pathinfo['dirname'];
        $dir = str_replace("./public/", "/public/", $dir);
        if ($width == 0) {
            $file_name = $GLOBALS['distribution_cfg']['OSS_DOMAIN'] . $dir . "/" . $file;
        } else {
            if ($height == 0) {
                $file_name = $GLOBALS['distribution_cfg']['OSS_DOMAIN'] . $dir . "/" . $file . "@" . $width . "w_1x.jpg";
            } else {
                if ($gen == 0) {
                    $file_name = $GLOBALS['distribution_cfg']['OSS_DOMAIN'] . $dir . "/" . $file . "@" . $width . "w_" . $height . "h_0c_1e_1x.jpg";
                } else {
                    $file_name = $GLOBALS['distribution_cfg']['OSS_DOMAIN'] . $dir . "/" . $file . "@" . $width . "w_" . $height . "h_1c_1e_1x.jpg";
                }
            }
        }
        //以短边缩放 1e 剪裁
        return $file_name;
    }
    if ($width == 0) {
        $new_path = $img_path;
    } else {
        $img_name = substr($img_path, 0, -4);
        $img_ext = substr($img_path, -3);
        if ($is_deleteable) {
            if ($is_preview) {
                $new_path = $img_name . "_" . $width . "x" . $height . ".jpg";
            } else {
                $new_path = $img_name . "o_" . $width . "x" . $height . ".jpg";
            }
        } else {
            if ($is_preview) {
                $new_path = $img_name . "" . $width . "" . $height . ".jpg";
            } else {
                $new_path = $img_name . "o" . $width . "" . $height . ".jpg";
            }
        }
        if (!file_exists(APP_ROOT_PATH . $new_path)) {
            require_once APP_ROOT_PATH . "system/utils/es_imagecls.php";
            $imagec = new es_imagecls();
            $thumb = $imagec->thumb(APP_ROOT_PATH . $img_path, $width, $height, $gen, true, "", $is_preview, $is_deleteable);
            if (app_conf("PUBLIC_DOMAIN_ROOT") != '') {
                $paths = pathinfo($new_path);
                $path = str_replace("./", "", $paths['dirname']);
                $filename = $paths['basename'];
                $pathwithoupublic = str_replace("public/", "", $path);
                $syn_url = app_conf("PUBLIC_DOMAIN_ROOT") . "/es_file.php?username="******"IMAGE_USERNAME") . "&password="******"IMAGE_PASSWORD") . "&file=" . get_domain() . APP_ROOT . "/" . $path . "/" . $filename . "&path=" . $pathwithoupublic . "/&name=" . $filename . "&act=0";
                @file_get_contents($syn_url);
            }
        }
    }
    return $new_path;
}
Пример #3
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;
}