思路:

1.数据库 创建test2 创建表img,字段id,url,addtime

2.前台页:

  1>我用的是bootstrap 引入必要的js,css

  2>引入美图秀秀的js

3.后台:图片上传

直接上代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>thinkphp+美图接口,实现图片上传+裁切</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/bootstrap.css"></head>
<style type="text/css">
html, body { height:100%; overflow:hidden; }
body { margin:0; }
</style>
<body>
<div class="container">
<div class="panel">
<a rowspan="3" class="text-center" data-toggle="modal" data-target="#head">
<notempty name="info">
<img id="img" src="{$info.url}" width="150px" class="img-rounded" />
<else/> <i class="glyphicon glyphicon-user" style="color:#6E6E6E; font-size:150px;"></i>
</notempty>
</a>
</div>
</div> <div class="modal fade" id="head" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<style>.modal-body object{ position:relative;}</style>
<div class="modal-body">
<div class="clearfix" style="position:absolute; width:100%; left:0px; right:0px;" >
<div id="altContent"></div>
</div>
<script src="__PUBLIC__/js/xiuxiu.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload=function(){
/*第1个参数是加载编辑器div容器,第2个参数是编辑器类型,第3个参数是div容器宽,第4个参数是div容器高*/
xiuxiu.embedSWF("altContent",5,"100%","400px",'headeditor');
//修改为您自己的图片上传接口
xiuxiu.setUploadURL("{:C('URL')}/index.php/Home/Upload/uploadImg.html");
xiuxiu.setUploadType(2);
//xiuxiu.setUploadDataFieldName("upload_file");
xiuxiu.onInit = function ()
{
xiuxiu.loadPhoto("{:C('URL')}{$info.url}");
}
xiuxiu.onBeforeUpload = function (data, id)
{
var size = data.size;
if(size > 2 * 1024 * 1024)
{
alert("图片不能超过2M");
return false;
}
return true;
}
xiuxiu.onUploadResponse = function (data)
{
//data=JSON.parse(data);
setTimeout(function(){
window.location.reload();
},1000);
//alert("上传响应" + data); //可以开启调试
}
// 调试
/*xiuxiu.onDebug = function (data)
{
alert("错误响应" + data);
}*/
}
</script>
</div>
</div>
</div>
</div> </body>
</html>

uploadcontroller.class.php

<?php
namespace Home\Controller;
use Think\Controller;
/**
* 图片上传
*/
class UploadController extends Controller
{
// 图片上传
public function uploadImg()
{ $upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = './image/'; // 设置附件上传目录
//$upload->savePath = 'img/'; // 设置附件上传目录
// 上传文件
$info = $upload->upload();
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
}else{// 上传成功
$where = array('id'=>1);
foreach ($info as $file) {
$savename = $upload->rootPath.$file['savepath'].$file['savename'];
$msg = M('Img')->where($where)->find();
if ($msg) {
$res = M('Img')->where($where)->setField('url',$savename);
}else{
$data = array(
'id' => 1,
'url' => $savename,
'addtime' => time()
);
$res = M('Img')->add($data);
}
$this->ajaxReturn(array('img'=>$savename,'status'=>1));
}
}
} } ?>

下载完整demo,带数据库sql文件

美图秀秀的详细开发文档:http://open.web.meitu.com/wiki/

thinkphp + 美图秀秀api 实现图片裁切上传,带数据库的更多相关文章

  1. 美图秀秀api实现图片的裁剪及美化

    美图秀秀不仅有PC版.手机版等客户端的软件,还有Web开方接口,可以在web页面上调用美图秀秀的api接口,实现图片的编辑.像淘宝.网易.qq空间.新浪微博等大厂都使用过该接口. 官网地址:http: ...

  2. iOS 图片部分模糊,类似于美图秀秀

    代码地址如下:http://www.demodashi.com/demo/14277.html 演示效果 演示效果 代码结构 项目结构截图如下: 该模块的核心源码部分为 MBPartBlurView, ...

  3. iOS开发系列--打造自己的“美图秀秀”

    --绘图与滤镜全面解析 概述 在iOS中可以很容易的开发出绚丽的界面效果,一方面得益于成功系统的设计,另一方面得益于它强大的开发框架.今天我们将围绕iOS中两大图形.图像绘图框架进行介绍:Quartz ...

  4. iOS开发系列--打造自己的“美图秀秀”

    概述 在iOS中可以很容易的开发出绚丽的界面效果,一方面得益于成功系统的设计,另一方面得益于它强大的开发框架.今天我们将围绕iOS中两大图形.图像绘图框架进行介绍:Quartz 2D绘制2D图形和Co ...

  5. 美图秀秀DBA谈MySQL运维及优化

    美图秀秀DBA谈MySQL运维及优化 https://mp.weixin.qq.com/s?__biz=MzI4NTA1MDEwNg==&mid=401797597&idx=2& ...

  6. 强大的Core Image(教你做自己的美图秀秀))

    iOS5新特性:强大的Core Image(教你做自己的美图秀秀))       iOS5给我们带来了很多很好很强大的功能和API.Core Image就是其中之一,它使我们很容易就能处理图片的各种效 ...

  7. iOS:iOS开发系列–打造自己的“美图秀秀”(下)

    来源: KenshinCui 链接:http://www.cnblogs.com/kenshincui/p/3959951.html 运行效果: 其他图形上下文 前面我们也说过,Quartz 2D的图 ...

  8. 美图秀秀 web开发图片编辑器

    美图秀秀web开发平台 http://open.web.meitu.com/wiki/ 1.环境配置 1.1.设置crossdomain.xml 下载crossdomain.xml文件,把解压出来的c ...

  9. PHP流式上传和表单上传(美图秀秀)

    最近需要开发一个头像上传的功能,找了很多都需要授权的,后来找到了美图秀秀,功能非常好用. <?php /** * Note:for octet-stream upload * 这个是流式上传PH ...

随机推荐

  1. 2、Runtime Area Data

    这个也分为两大部分 1.是线程共享区域 ·线程共享区域又包括两部分Heap(堆)和方法区(Perm) 2.是线程独享区域 这个也包括两大部分程序计数器和栈 栈(又包括两部分:VM 栈和本地方法栈)

  2. js函数自动执行的一点理解

    //声明一个匿名函数并赋值给一个变量 var a = function(){ console.log("executing..."); } //匿名函数调用 a(); 相信上面这段 ...

  3. android 开发中fragment 遇到的问题

    http://yifeng.studio/2016/12/15/android-fragment-attentions/ 1.不要轻易在 fragment中引用 getactivity(); 解决方案 ...

  4. 会游走的TextView

    //自定义的TextView package com.bwie.androidtest; import android.content.Context; import android.graphics ...

  5. centos 6 SSH配置Google Authentication 验证

    创建工作目录: mkdir google-authentication 1. 安装二维码生成依赖 #wget http://fukuchi.org/works/qrencode/qrencode-3. ...

  6. IntelliJ IDEA手工安python装插件方法

    IntelliJ IDEA手工安装插件方法 以IntelliJ IDEA 11.0.1安装python为例: (1)下载python插件地址:http://plugins.intellij.net/p ...

  7. iOS 视频录制、压缩、上传

    项目中实现功能 视频的录制.压缩.上传 首先调用系统的相机或相册 iOS录制的视频是mov格式的,安卓和PC不支持,因此要转换成MP4,并且要压缩. 获取到视频或者照片,处理的方法 下面两个方法是获取 ...

  8. portotype

    [  portotype  ] [语法] function :function Name是创建新的函数的名称 body : body可以选项,包含调用该函数时被执行的JScrtipt 代码的字符串. ...

  9. console对象

    今天无意中看到console.info()的时候不自觉的楞了一下,对于console.info()确实不是十分的了解,平时就是用console.log(),既然不太明白就去网上看了一下关于consol ...

  10. Xcode6 storyboard new push segue 后的视图控制器没有navigation item bug.

    手动切一下 老的push,再切回来,就会出有了,我想是一个bug. Xcode 6 Segue with UINavigationItem up vote0down votefavorite   I' ...