Beispiel #1
0
 public function update()
 {
     if ($this->mNeedCheckIn && !$this->prms['manage']) {
         $this->errorOutput(NO_OPRATION_PRIVILEGE);
     }
     if (empty($this->input['id'])) {
         $this->errorOutput('水印名称不能为空');
     }
     if (empty($this->input['config_name'])) {
         $this->errorOutput('配置名称不能为空');
     }
     if (intval($this->input['water_type']) == 1 && empty($this->input['water_filename'])) {
         $this->errorOutput('水印图片不能为空');
     }
     if (intval($this->input['water_type']) == 0 && empty($this->input['water_text'])) {
         $this->errorOutput('水印文字不能为空');
     }
     $id = intval($this->input['id']);
     $config_name = urldecode($this->input['config_name']);
     switch (intval($this->input['water_type'])) {
         case 0:
             //文字水印
             if (empty($this->input['water_text'])) {
                 $this->errorOutput('水印文字不能为空');
             }
             $water = array('config_name' => $config_name, 'type' => 0, 'position' => intval($this->input['get_photo_waterpos']), 'filename' => '', 'margin_x' => intval($this->input['margin_x']), 'margin_y' => intval($this->input['margin_y']), 'condition_x' => intval($this->input['condition_x']), 'condition_y' => intval($this->input['condition_y']), 'water_text' => urldecode($this->input['water_text']), 'water_angle' => intval($this->input['water_angle']) ? intval($this->input['water_angle']) : 1, 'water_font' => urldecode($this->input['water_font']), 'font_size' => intval($this->input['font_size']), 'opacity' => urldecode($this->input['opacity']), 'water_color' => urldecode($this->input['water_color']), 'global_default' => $this->input['default'] ? 1 : '');
             $ret = $this->obj->update($water, $id);
             if ($water['global_default']) {
                 $this->obj->update_water_nodefault($id);
             }
             break;
         case 1:
             //图片水印
             if (empty($this->input['water_filename'])) {
                 $this->errorOutput('水印图片不能为空');
             }
             $water_name = urldecode($this->input['water_filename']);
             $water = array('config_name' => $config_name, 'type' => 1, 'position' => intval($this->input['get_photo_waterpos']), 'filename' => $water_name, 'margin_x' => intval($this->input['margin_x']), 'margin_y' => intval($this->input['margin_y']), 'condition_x' => intval($this->input['condition_x']), 'condition_y' => intval($this->input['condition_y']), 'water_text' => '', 'water_angle' => '', 'water_font' => '', 'font_size' => '', 'opacity' => urldecode($this->input['opacity']), 'water_color' => '', 'global_default' => $this->input['default'] ? 1 : '');
             $ret = $this->obj->update($water, $id);
             if ($water['global_default']) {
                 $this->obj->update_water_nodefault($id);
             }
             //移动水印图片
             $temp_file = hg_getimg_default_dir() . MATERIAL_TMP_PATH . $water_name;
             $path = hg_getimg_default_dir() . WATER_PATH;
             if (!hg_mkdir($path)) {
                 return false;
             }
             if (file_exists($temp_file)) {
                 @copy($temp_file, $path . $water_name);
             }
             break;
         default:
             break;
     }
     hg_unlink_file(CACHE_DIR, '.water.cache.php');
     //删除水印缓存文件
     if ($ret) {
         $data = array('update_time' => TIMENOW);
         $this->obj->update($data, $id);
         $this->addLogs('修改水印配置', '', $water, $water['config_name']);
     }
     $this->addItem('success');
     $this->output();
 }
Beispiel #2
0
 /**
  * 根据路径、文件名删除图片
  * Enter description here ...
  */
 function delMaterialNodb()
 {
     if (empty($this->input['path'])) {
         $this->errorOutput(NOPATH);
     }
     if (empty($this->input['filename'])) {
         $this->errorOutput(NONAME);
     }
     $path = $this->input['path'];
     $filename = $this->input['filename'];
     hg_editTrue_material(hg_getimg_default_dir() . $path, $filename);
     hg_delete_material(hg_getimg_default_dir() . $path, $filename);
     $this->addItem('true');
     $this->output();
 }
Beispiel #3
0
 private function addMaterialNodb_file()
 {
     $dir = urldecode($this->input['dir']);
     $name = $this->input['name'];
     $dir[strlen($dir) - 1] == '/' ? $dir = $dir : ($dir = $dir . '/');
     if ($_FILES['Filedata']) {
         if ($_FILES['Filedata']['error']) {
             return false;
         } else {
             if (!$name) {
                 $filename = $_FILES['Filedata']['name'];
             } else {
                 $filename = $name;
             }
             $path = hg_getimg_default_dir() . $dir;
             if (!hg_mkdir($path)) {
                 return false;
             } else {
                 if (file_exists($path . $filename)) {
                     $json = preg_replace('/(.*?\\.).*?/siU', "\\1json", $filename);
                     if (file_exists($path . $json)) {
                         $info = json_decode(file_get_contents($path . $json), true);
                         if (!empty($info['thumb'])) {
                             foreach ($info['thumb'] as $k => $v) {
                                 if (is_file($v) && file_exists($v)) {
                                     @unlink($v);
                                 }
                             }
                         }
                     }
                 }
                 if (!move_uploaded_file($_FILES["Filedata"]["tmp_name"], $path . $filename)) {
                     return false;
                 } else {
                     $info = array();
                     $info['host'] = hg_getimg_default_host();
                     $info['dir'] = $dir;
                     $info['filename'] = $filename;
                     return $info;
                 }
             }
         }
     }
 }
Beispiel #4
0
 public function water_upload()
 {
     $typetmp = explode('.', $_FILES['Filedata']['name']);
     $filetype = strtolower($typetmp[count($typetmp) - 1]);
     //验证文印图片格式
     include_once CUR_CONF_PATH . 'lib/cache.class.php';
     $this->cache = new cache();
     $material_type = $this->cache->check_cache('material_type.cache.php');
     $type = '';
     if (!empty($material_type)) {
         foreach ($material_type as $k => $v) {
             if (in_array($filetype, array_keys($v))) {
                 $type = $k;
             }
         }
     }
     if ($type != 'img') {
         return false;
     }
     $filename = date('YmdHis') . hg_generate_user_salt(4) . '.' . $filetype;
     //上传到临时目录
     $path = hg_getimg_default_dir() . MATERIAL_TMP_PATH;
     if (!hg_mkdir($path)) {
         return false;
     } else {
         if (!move_uploaded_file($_FILES["Filedata"]["tmp_name"], $path . $filename)) {
             return false;
         } else {
             $info['filename'] = $filename;
             $info['path'] = MATERIAL_TMP_PATH;
             $info['url'] = hg_material_link(hg_getimg_default_host(), MATERIAL_TMP_PATH, '', $filename);
             return $info;
         }
     }
 }
Beispiel #5
0
/**
 * 创建图片
 * @param $uploadedfile 需生成的图片路径
 * @param $name 生成后的返回的图片名称
 * @param $path 需要存放的图片上级目录
 * @param $size 缩略图的尺寸(array)
 * @param $max_pixel 尺寸的最大值(M)
 * @param $force 当文件存在时是否强制重新生成
 * return 生成后的图片名
 */
function hg_mk_images($uploadedfile, $name, $path, $size, $water, $max_pixel = 100, $force = 0)
{
    $special = '';
    if (!file_exists($uploadedfile) || !$name || !$path || !is_array($size)) {
        return false;
    }
    include_once ROOT_PATH . 'lib/class/gdimage.php';
    //源文件
    if (filesize($uploadedfile) / 1024 / 1024 >= $max_pixel) {
        return false;
    }
    $image = getimagesize($uploadedfile);
    $width = $image[0];
    $height = $image[1];
    //从 JPEG 或 TIFF 文件中读取 EXIF 头信息 相机照片缩略图旋转问题
    if ($image[2] == 2) {
        @($exif = exif_read_data($uploadedfile));
        if (!empty($exif['Orientation'])) {
            switch ($exif['Orientation']) {
                case 8:
                    $tmp = $width;
                    $width = $height;
                    $height = $tmp;
                    break;
                case 3:
                    break;
                case 6:
                    $tmp = $width;
                    $width = $height;
                    $height = $tmp;
                    break;
            }
        }
    }
    //从 JPEG 或 TIFF 文件中读取 EXIF 头信息 相机照片缩略图旋转问题
    $file_name = $name;
    //目录
    $file_dir = $path;
    //文件路径
    $file_path = $uploadedfile;
    $img = new GDImage();
    if ($size['label']) {
        $new_name = $file_name;
        $other_dir = "";
        if (empty($size['other_dir'])) {
            $other_dir = date('Y') . '/' . date('m') . '/';
        } else {
            $other_dir = $size['other_dir'];
        }
        hg_mkdir($file_dir . $size['label'] . '/' . $other_dir);
        $save_file_path = $file_dir . $size['label'] . '/' . $other_dir . $new_name;
    } else {
        hg_mkdir($file_dir);
        $save_file_path = $file_dir . $file_name;
    }
    if (!file_exists($save_file_path) || $force) {
        $img->init_setting($file_path, $save_file_path);
        if ($size['height'] == 1) {
            if ($width > $height) {
                if ($size['width']) {
                    $img->maxWidth = $width > $size['width'] ? $size['width'] : $width;
                    $img->maxHeight = $height * ($img->maxWidth / $width);
                }
            } else {
                if ($size['width']) {
                    $img->maxHeight = $height > $size['width'] ? $size['width'] : $height;
                    $img->maxWidth = $width * ($img->maxHeight / $height);
                }
            }
        } else {
            if (empty($size['width'])) {
                $img->maxHeight = $height > $size['height'] ? $size['height'] : $height;
                $img->maxWidth = $width * ($img->maxHeight / $height);
            } else {
                if ($width > $height) {
                    if ($size['width']) {
                        $img->maxWidth = $width > $size['width'] ? $size['width'] : $width;
                        if ($size['height']) {
                            $img->maxHeight = $height > $size['height'] ? $size['height'] : $height;
                        } else {
                            $img->maxHeight = $height * ($img->maxWidth / $width);
                        }
                    }
                } else {
                    if ($size['height']) {
                        if ($height / $width > 1.2 && $size['width'] / $size['height'] > 1.2) {
                            $special = 1;
                            //$img->maxHeight = $height > $size['height'] ? $size['height'] : $height;
                            //$img->maxWidth = $width * ($img->maxHeight/$height);
                            $img->maxHeight = $height > $size['height'] ? $size['height'] : $height;
                            $img->maxWidth = $width > $size['width'] ? $size['width'] : $width;
                        } else {
                            $img->maxHeight = $height > $size['height'] ? $size['height'] : $height;
                            $img->maxWidth = $width > $size['width'] ? $size['width'] : $width;
                        }
                    } else {
                        $img->maxWidth = $width > $size['width'] ? $size['width'] : $width;
                        $img->maxHeight = $height * ($img->maxWidth / $width);
                    }
                }
            }
        }
        $isSucc = $img->makeThumb(3, FALSE);
        if (!$isSucc) {
            return false;
        }
        if ($special) {
            //hg_add_backgroud($save_file_path, $size);
        }
    }
    if (!empty($water)) {
        if ($water['type'] == 1) {
            $water['water_file_path'] = $water['filename'] ? hg_getimg_default_dir() . WATER_PATH . $water['filename'] : '';
            $img->waterimg($save_file_path, $water);
        } else {
            $water['water_font'] = $water['water_font'] ? CUR_CONF_PATH . 'font/' . $water['water_font'] : CUR_CONF_PATH . 'font/arial.ttf';
            $water['font_size'] = $water['font_size'] ? $water['font_size'] : 14;
            $img->waterstr($save_file_path, $water);
        }
    }
    return $file_name;
}