Thinkphp上传图片手动剪切功能谁有?tp框架 30

亲们谁有这功能插件?Thinkphp3.1.3的... 亲们谁有这功能插件?Thinkphp3.1.3的 展开
 我来答
水·莲·月
2016-04-15
知道答主
回答量:52
采纳率:0%
帮助的人:17.8万
展开全部
<?php
include 'config.php';

class controller
{

    // ajax 上传头像图片
    public function ajax_upload_avatar()
    {
        include('models'.DIRECTORY_SEPARATOR.'uploader.php');

        $uploader = new uploader( explode(', ', ALLOW_UPLOAD_IMAGE_TYPES), MAX_UPLOAD_SIZE );

        $result = $uploader->upload( 'tmp'.DIRECTORY_SEPARATOR );    // 先保存到临时文件夹

        $reponse = new stdClass();
        if( isset($result['success']) && $result['success'] )
        {
            include('models'.DIRECTORY_SEPARATOR.'gd.php');

            $src_path = 'tmp'.DIRECTORY_SEPARATOR.$uploader->get_real_name();

            $gd = new gd();
            $gd->open( $src_path );
            if( $gd->is_image() )
            {
                if( $gd->get_width() < AVATAR_WIDTH )
                {
                    $reponse->success = false;    // 传递给 file-uploader 表示服务器端已处理
                    $reponse->description = '您上传的图片宽度('.$gd->get_width().'像素)过小!最小需要'.AVATAR_WIDTH.'像素。';
                }
                else if( $gd->get_height() < AVATAR_HEIGHT )
                {
                    $reponse->success = false;    // 传递给 file-uploader 表示服务器端已处理
                    $reponse->description = '您上传的图片高度('.$gd->get_height().'像素)过小!最小需要'.AVATAR_HEIGHT.'像素。';
                }
                else
                {
                    $reponse->success = true;
                    $reponse->tmp_avatar = $uploader->get_real_name();

                    if($gd->get_width()>AVATAR_MAX_WIDTH || $gd->get_height() > AVATAR_MAX_HEIGHT)
                    {
                        // 图片过大时按比例缩小,防止超大图片撑破页面
                        $gd->resize_to(AVATAR_MAX_WIDTH, AVATAR_MAX_HEIGHT, 'scale');
                        $gd->save_to( $src_path );
                    }
                }
            }
        }
        else if( isset($result['error']) )
        {
            $reponse->success = false;
            $reponse->description = $result['error'];
        }

        header('Content-type: application/json');
        echo json_encode($reponse);
    }

    // ajax 裁切头像图片
    public function ajax_crop()
    {
        $tmp_avatar = $_POST['tmp_avatar'];
        $x1 = $_POST['x1'];
        $y1 = $_POST['y1'];
        $x2 = $_POST['x2'];
        $y2 = $_POST['y2'];
        $w = $_POST['w'];
        $h = $_POST['h'];

        $reponse = new stdClass();

        $src_path = 'tmp'.DIRECTORY_SEPARATOR.$tmp_avatar;
        if(!file_exists($src_path))
        {
            $reponse->success = false;
            $reponse->description = '未找到图片文件';
        }
        else
        {
            include('models'.DIRECTORY_SEPARATOR.'gd.php');
            $gd = new gd();
            $gd->open( $src_path );
            if( $gd->is_image() )
            {
                $gd->crop($x1, $y1, $w, $h);
                $gd->resize_to(AVATAR_WIDTH, AVATAR_HEIGHT, 'scale_fill');

                $avatar_name = date('YmdHis').'_'.md5(uniqid()).'.'.$gd->get_type();
                $gd->save_to( 'avatars'.DIRECTORY_SEPARATOR.$avatar_name );

                setcookie('avatar', $avatar_name, time()+86400*30);    // 本示例程序仅在 cookie 中保存 
                /*

                实际应用中会有更多 保存头像代码

                ......

                */

                @unlink($src_path);

                $reponse->success = true;
                $reponse->avatar = $avatar_name;

                

                $reponse->description = '';
            }
            else
            {
                $reponse->success = false;
                $reponse->description = '该图片文件不是有效的图片';
            }
        }

        header('Content-type: application/json');
        echo json_encode($reponse);
    }
}

$task = isset($_GET['task'])?$_GET['task']:'';
if($task!='')
{
    $instance = new controller();
    $instance->$task();
}
?>
匿名用户
2015-05-08
展开全部
<?php
return array(
'URL_MODEL' => 2, // 如果你的环境不支持PATHINFO 请设置为3
'DB_TYPE' => 'mysql',
'DB_HOST' => 'localhost',
'DB_NAME' => 'thinkphp',
'DB_USER' => 'root',
'DB_PWD' => '',
'DB_PORT' => '3306',
'DB_PREFIX' => 'tp_',

'SHOW_PAGE_TRACE' =>true, //显示页面调试明细

'TMPL_PARSE_STRING' => array( // 地址替换,用_UPLOAD_目录 代替 根目录下的Upload目录
'__UPLOAD__' => __ROOT__.'/Uploads',
),
);
?>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式