0

0

php版本 上妆程序 给图片添加饰物

php中文网

php中文网

发布时间:2016-06-13 11:16:18

|

1293人浏览过

|

来源于php中文网

原创

php版本 化妆程序 给图片添加饰物

大家估计都用手机玩过 化妆整人的程序

也就是对照片加工处理 添加饰物 然后生成一张图片 可以搞笑娱乐大家

?

e网企业2.0
e网企业2.0

一款适用于中小企业自助建站程序,是c#与xml技术相结合的产物,支持动态设定二级栏目,采用了开放式架构,建站模版自由添加。程序整合了(单一文本,新闻列表,图片列表 ,在线订单, 文件下载 , 留言板)六类插件,以所见即所得的方式,将烦锁的建站过程简化到三步,使用户可以轻松上手。 管理后台:manage.aspx 初始密码均为admin

下载

?

立即学习PHP免费学习笔记(深入)”;

?

本文主要采用的技术有

1.jquery的拖拽 drag& drop技术

2.PHP转换Json data

3.CSS3 +HTML5

?

首先我们建立一个大体的框架

php版本 上妆程序 给图片添加饰物
el
el
el

?采用的css 

#content{    position:relative;    width:1105px;    height:500px;    margin:40px auto 0px auto;    background-color:#F9F9F9;    -moz-border-radius:6px;    -webkit-border-radius:6px;    border-radius:6px;    -moz-box-shadow:0px 0px 8px #ccc;    -webkit-box-shadow:0px 0px 8px #ccc;    box-shadow:0px 0px 8px #ccc;}.background{    position:absolute;    width:640px;    height:480px;    top:10px;    left:215px;    -moz-box-shadow:0px 0px 3px #bbb;    -webkit-box-shadow:0px 0px 3px #bbb;    box-shadow:0px 0px 3px #bbb;}

?然后是拖拽的元素和图片的 css样式

?

#objects{    width:210px;    height:486px;    top:10px;    left:10px;    position:absolute;}.obj_item{    width:70px;    height:70px;    float:left;}#tools{    width:230px;    top:8px;    right:10px;    position:absolute;    height:420px;    overflow-y:scroll;    overflow-x:hidden;}.item{    border:3px solid #fff;    background-color:#ddd;    height:60px;    position:relative;    margin:2px 5px 2px 2px;    -moz-border-radius:3px;    -webkit-border-radius:3px;    border-radius:3px;    -moz-box-shadow:0px 0px 2px #999;    -webkit-box-shadow:0px 0px 2px #999;    box-shadow:0px 0px 2px #999;}.thumb{    width:50px;    height:50px;    margin:5px;    float:left;}.slider{    float: left;    width: 115px;    margin: 30px 0px 0px 5px;    background-color:#fff;    height:10px;    position:relative;}.slider span{    font-size:10px;    font-weight:normal;    margin-top:-25px;    float:left;}.slider span.degrees{    position:absolute;    right:-22px;    top:20px;    width:20px;    height:20px;}.slider .ui-slider-handle {    width:10px;    height:20px;    outline:none;}a.remove{    width:16px;    height:16px;    position:absolute;    top:0px;    right:0px;    background:transparent url(../images/cancel.png) no-repeat top left;    opacity:0.5;    cursor:pointer;}a.remove:hover{    opacity:1.0;}

?

饰品元素 被存储在json data中

var data = {    "images": [        {"id" : "obj_0" ,"src" : "background.jpg", "width" : "640", "height" : "480"}    ]};

?另外元素可以放大缩小 并且可以拖拽

$('#objects img').resizable({    handles : 'se',    stop    : resizestop}).parent('.ui-wrapper').draggable({    revert  : 'invalid'});

?

$('#background').droppable({    accept  : '#objects div', /* accept only draggables from #objects */    drop    : function(event, ui) {        var $this       = $(this);        ++count_dropped_hits;        var draggable_elem = ui.draggable;        draggable_elem.css('z-index',count_dropped_hits);        /* object was dropped : register it */        var objsrc      = draggable_elem.find('.ui-widget-content').attr('src');        var objwidth    = parseFloat(draggable_elem.css('width'),10);        var objheight   = parseFloat(draggable_elem.css('height'),10);         /* for top and left we decrease the top and left of the droppable element */        var objtop      = ui.offset.top - $this.offset().top;        var objleft     = ui.offset.left - $this.offset().left;         var objid       = draggable_elem.find('.ui-widget-content').attr('id');        var index       = exist_object(objid);        if(index!=-1) { //if exists update top and left            data.images[index].top  = objtop;            data.images[index].left = objleft;        }        else{            /* register new one */            var newObject = {                'id'        : objid,                'src'       : objsrc,                'width'     : objwidth,                'height'    : objheight,                'top'       : objtop,                'left'      : objleft,                'rotation'  : '0'            };            data.images.push(newObject);            /* add object to sidebar*/             $('

?下面是整体的php文件

$res = JSON_decode(stripslashes($_POST['JSONdata']), true);/* get data */$count_images   = count($res['images']);/* the background image is the first one */$background     = $res['images'][0]['src'];$photo1         = imagecreatefromjpeg($background);$foto1W         = imagesx($photo1);$foto1H         = imagesy($photo1);$photoFrameW    = $res['images'][0]['width'];$photoFrameH    = $res['images'][0]['height'];$photoFrame     = imagecreatetruecolor($photoFrameW,$photoFrameH);imagecopyresampled($photoFrame, $photo1, 0, 0, 0, 0, $photoFrameW, $photoFrameH, $foto1W, $foto1H); /* the other images */for($i = 1; $i < $count_images; ++$i){    $insert         = $res['images'][$i]['src'];    $photoFrame2Rotation = (180-$res['images'][$i]['rotation']) + 180;     $photo2         = imagecreatefrompng($insert);     $foto2W         = imagesx($photo2);    $foto2H         = imagesy($photo2);    $photoFrame2W   = $res['images'][$i]['width'];    $photoFrame2H   = $res['images'][$i]['height'];     $photoFrame2TOP = $res['images'][$i]['top'];    $photoFrame2LEFT= $res['images'][$i]['left'];     $photoFrame2    = imagecreatetruecolor($photoFrame2W,$photoFrame2H);    $trans_colour   = imagecolorallocatealpha($photoFrame2, 0, 0, 0, 127);    imagefill($photoFrame2, 0, 0, $trans_colour);     imagecopyresampled($photoFrame2, $photo2, 0, 0, 0, 0, $photoFrame2W, $photoFrame2H, $foto2W, $foto2H);     $photoFrame2    = imagerotate($photoFrame2,$photoFrame2Rotation, -1,0);    /*after rotating calculate the difference of new height/width with the one before*/    $extraTop       =(imagesy($photoFrame2)-$photoFrame2H)/2;    $extraLeft      =(imagesx($photoFrame2)-$photoFrame2W)/2;     imagecopy($photoFrame, $photoFrame2,$photoFrame2LEFT-$extraLeft, $photoFrame2TOP-$extraTop, 0, 0, imagesx($photoFrame2), imagesy($photoFrame2));}// Set the content type header - in this case image/jpegheader('Content-type: image/jpeg');imagejpeg($photoFrame, $targetfile);imagedestroy($photoFrame);

?

相关文章

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
苹果官网入口直接访问
苹果官网入口直接访问

苹果官网直接访问入口是https://www.apple.com/cn/,该页面具备0.8秒首屏渲染、HTTP/3与Brotli加速、WebP+AVIF双格式图片、免登录浏览全参数等特性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

115

2025.12.24

拼豆图纸在线生成器
拼豆图纸在线生成器

拼豆图纸生成器有PixelBeads在线版、BeadGen和“豆图快转”;推荐通过pixelbeads.online或搜索“beadgen free online”直达官网,避开需注册的诱导页面。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

82

2025.12.24

俄罗斯搜索引擎yandex官方入口地址(最新版)
俄罗斯搜索引擎yandex官方入口地址(最新版)

Yandex官方入口网址是https://yandex.com。用户可通过网页端直连或移动端浏览器直接访问,无需登录即可使用搜索、图片、新闻、地图等全部基础功能,并支持多语种检索与静态资源精准筛选。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

546

2025.12.24

JavaScript ES6新特性
JavaScript ES6新特性

ES6是JavaScript的根本性升级,引入let/const实现块级作用域、箭头函数解决this绑定问题、解构赋值与模板字符串简化数据处理、对象简写与模块化提升代码可读性与组织性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

150

2025.12.24

php框架基础知识汇总
php框架基础知识汇总

php框架是构建web应用程序的架构,提供工具和功能,以简化开发过程。选择合适的框架取决于项目需求和技能水平。实战案例展示了使用laravel构建博客的步骤,包括安装、创建模型、定义路由、编写控制器和呈现视图。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

20

2025.12.24

Word 字间距调整方法汇总
Word 字间距调整方法汇总

本专题整合了Word字间距调整方法,阅读下面的文章了解更详细操作。

47

2025.12.24

任务管理器教程
任务管理器教程

本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。

7

2025.12.24

AppleID格式
AppleID格式

本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。

12

2025.12.24

csgo视频观看入口合集
csgo视频观看入口合集

本专题整合了csgo观看入口合集,阅读下面的文章了知道更多入口地址。

371

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

相关下载

更多

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
JS轻松实现打地鼠游戏
JS轻松实现打地鼠游戏

共6课时 | 0.7万人学习

JS轻松实现打地鼠游戏
JS轻松实现打地鼠游戏

共6课时 | 0.7万人学习

CSS深入理解之border视频教程
CSS深入理解之border视频教程

共7课时 | 1.3万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号