1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/icret-easyImages

Клонировать/Скачать
api.php 3.6 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
icret Отправлено 23.05.2019 15:12 391e846
<?php
// 载入文件
require './lib/class.upload.php';
require './lib/func.php';
// 检查是否开启api
apiStatus();
// 打开共功域
header('Access-Control-Allow-Origin:*');
// 图片上传处理
$handle = new upload($_FILES['file'],$config['language']);
if ($handle->uploaded){
// 图片重命名
$handle->file_new_name_body = 'api_'.config_rename();
// 允许上传大小
$handle->file_max_size = $config['maxSize'];
// 允许上传的mime类型
$handle->allowed = array ('image/*');
//
// 设置PNG图片的压缩级别
$handle->png_compression = $config['png_zip'];
// 设置jpeg图片的压缩级别
$handle->jpeg_quality = $config['jpeg_zip'];
// 设置转换上传图片为指定格式
$handle->image_convert = $config['imgConvert'];
// 限制最小上传图片宽度
$handle->image_min_width = $config['image_min_w'];
// 限制最小上传图片高度
$handle->image_min_height = $config['image_min_h'];
// 裁剪图片
if ($config['image_resize']){
$handle->image_resize = true;
if ($config['image_ratio']){
$handle->image_ratio = true;
$handle->image_x = $config['image_x'];
$handle->image_y = $config['image_y'];
}else{
$handle->image_x = $config['image_x'];
$handle->image_y = $config['image_y'];
}
}
// 调用水印
if ($config['watermark'] > 0){
switch ($config['watermark']){
case 1: // 文字水印 过滤gif
if (isAnimatedGif($handle->file_src_pathname)===0){
$handle->image_text = $apiWaterText;
$handle->image_text_direction = $config['textDirection'];
$handle->image_text_color = $config['textColor'];
$handle->image_text_opacity = $config['textOpacity'];
$handle->image_text_font = $config['textFont'];
$handle->image_text_padding = $config['textPadding'];
$handle->image_text_position = $config['waterPosition'];
// 设置背景色
if ($config['text_bg_set']){
$handle->image_text_background = $config['text_water_bg'];
$handle->image_text_background_opacity = $config['text_bg_opa'];
}
}
break;
case 2: // 图片水印
if (isAnimatedGif($handle->file_src_pathname)===0){
$handle->image_watermark = $config['waterImg'];
$handle->image_watermark_position = $config['waterPosition'];
$handle->image_watermark_no_zoom_in = true;
$handle->image_watermark_no_zoom_out = true;
}
break;
default:
echo $handle->error;
break;
}
}
// 存储图片路径:images/201807/
$handle->process(config_path());
// 图片完整相对路径:images/201807/0ed7ccfd4dab9cbc.jpg
if ($handle->processed){
header('Content-type:text/json');
// 上传成功后返回json数据
$reJson = array (
"result" => 'success',
"url" => $config['domain'].config_path().$handle->file_dst_name,
);
echo json_encode($reJson);
$handle->clean();
}else{
// 上传错误 返回错误信息
$reJson = array (
"result" => 'failed',
"message" => $handle->error
);
echo json_encode($reJson);
echo $handle->error;
}
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/icret-easyImages.git
git@api.gitlife.ru:oschina-mirror/icret-easyImages.git
oschina-mirror
icret-easyImages
icret-easyImages
master