前言:想到用户资料中一般有个图像自我截取的部分,为什么要截取呢,因为好看了。so,经过我各种百度,各种参考,终于打工搞成了,写下纪念纪念,让以后拿来就用也好。

一:想前端ui这东西,我就懒得说话了,哎,没艺术啊!毫不犹豫的选择上网找资料了,发现一般有两种方法1:Jcrop;2:imgAreaSelect;呵呵,我选了imgAreaSelect;使用很简单么?

二:获取这个插件包:点我就来了开心吧!

三:使用方法简介:

$('#img').imgAreaSelect({

  各种参数配置,回调函数

});

$('img#select').imgAreaSelect({
selectionColor:'blue', //截取颜色
    //看名字就知道了,截取部分的左上右下的点坐标哦
x1:0,y1:0,x2:50,y2:50,
maxWidth:400,maxHeitht:400, //限定的截取部分宽高:
minWidth:50,minHeight:50,
selectionOpacity:0.1, //截取的透明度
handles: true, //截取边框的小柄
aspectRatio:'1:1', //固定比例大小
onSelectEnd:preview //截取操作完后,需要获取什么的函数,自定义 });

官网在这     百度文库中文对译部分:         他人博客:

-------------------------------------------------------------------------

四:附加解释说明,经过上方各种链接可能聪明的你已经有点不懂了

(截取的原理):

1:给定你想选择显示截取后的大小:比如200

2:实际你截取的大小:select_width:

3: 显示比例:scale  = 200 / (selection.width || 1);

4: 如何显示呢?把原图按此比例扩大,然后在控制边距以  -x,-y,偏移

  回调函数部分:

    var scaleX = 200 / (selection.width || 1);
var scaleY = 200 / (selection.height || 1); var scaleX1 = 100 / (selection.width || 1);
var scaleY1 = 100 / (selection.height || 1); $('#preview200').css({
width: Math.round(scaleX * 300) + 'px',
height: Math.round(scaleY * 300) + 'px',
marginLeft: '-' + Math.round(scaleX*selection.x1) + 'px',
marginTop: '-' + Math.round(scaleY*selection.y1) + 'px' });

五:好了,激动人心的时候来了,请看图:

参考代码:不含服务端对图像的截取

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图像选取</title> <link rel="stylesheet" type="text/css" href="css/imgareaselect-default.css" />
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery.imgareaselect.pack.js"></script>
<script type="text/javascript" src="../_uploadfilecheck.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('img#select').imgAreaSelect({
selectionColor:'blue',
x1:0,y1:0,x2:50,y2:50,
maxWidth:400,maxHeitht:400,
minWidth:50,minHeight:50,
selectionOpacity:0.1,
handles: true,
aspectRatio:'1:1',
onSelectEnd:preview });
$("#button1").click(function(){
if(checkImgType($("#imgFile")[0])){
$(this).parent().submit(); }
}); $("#button2").click(function(){
alert($(this).parent().submit());
});
})
function getValue(selection){
$('input[name="x1"]').val(selection.x1);
$('input[name="y1"]').val(selection.y1);
$('input[name="width"]').val(selection.width);
$('input[name="height"]').val(selection.height);
}
function preview(img, selection) {
if(selection.width>49){
getValue(selection);
var scaleX = 200 / (selection.width || 1);
var scaleY = 200 / (selection.height || 1); var scaleX1 = 100 / (selection.width || 1);
var scaleY1 = 100 / (selection.height || 1); $('#preview200').css({
width: Math.round(scaleX * 300) + 'px',
height: Math.round(scaleY * 300) + 'px',
marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
marginTop: '-' + Math.round(scaleY * selection.y1) + 'px' });
$('#preview100').css({
width: Math.round(scaleX1 * 300) + 'px',
height: Math.round(scaleY1 * 300) + 'px',
marginLeft: '-' + Math.round(scaleX1* selection.x1) + 'px',
marginTop: '-' + Math.round(scaleY1 * selection.y1) + 'px' }); }
} </script> <style type="text/css">
#container{
// position:absolute;
// left:40px;
// background:#FFF; border:#666 2px solid;
border-radius:10px;
width:600px;
height:500px;
padding:20px;
}
#selectdiv{
width:350px;
height:550px;
float:left;
// border-right:#666 2px solid;
// border:#666 2px solid;
}
#uploaddiv{
margin-top:20px;
border-top:#CCC 1px solid;
}
#prediv200{
height:200px;
width:200px;
overflow:hidden;
border:#CCC 3px dashed;
}
#prediv100{
height:100px;
width:100px;
overflow:hidden;
border:#CCC 3px dashed;
}
#preview{
position:relative;
overflow:hidden;
}
[type=button]{
width:50px;
}
</style>
</head> <body> <div id="container"> <div id="selectdiv">
<img id="select" src="26.jpg" width="300px" height="300px" /> <div>
<p>图片上传:<font color='red'>*.gif,*.jpg,*.png,*.bmp</font></p> <form>
<input type="file" name="imgFile" id="imgFile"><br /><br />
<input type="button" value="上传" id="button1"/>
</form>
</div>
</div> <div id="prediv200">
<img id="preview200" src="26.jpg" width="200px" height="200px" />
</div> <div id="prediv100">
<img id="preview100" src="26.jpg" width="100px" height="100px" />
</div> <div>
<form>
<input type="hidden" name="x1" value="0" />
<input type="hidden" name="y1" value="0" />
<input type="hidden" name="width" value="100" />
<input type="hidden" name="height" value="100" />
<br /><br />
<input type="button" value="修改" id="button2"/>
</form>
</div>
</div> </body>
</html>

文件上传验证js:

 /**检查图片上传类型*/
function checkImgType(obj){ var imgFile = '';
//获取图片的全路径
var imgFilePath = getImgFullPath(obj);
var endIndex = imgFilePath.lastIndexOf("\\");
var lastIndex = imgFilePath.length-endIndex-1;
if (endIndex != -1)
imgFile= imgFilePath.substr(endIndex+1,lastIndex);
else
imgFile = imgFilePath; var tag = true;
endIndex = imgFilePath.lastIndexOf(".");
if (endIndex == -1)
tag = false; var ImgName = imgFilePath.substr(endIndex+1,lastIndex);
ImgName = ImgName.toUpperCase(); if (ImgName !="GIF" && ImgName !="JPG" && ImgName !="PNG" && ImgName !="BMP"){
tag=false;
}
if (!tag) {
alert("上传图片的文件类型必须为: *.gif,*.jpg,*.png,*.bmp,请重新选择!")
alert("你逗我么");
// Upload.clear(obj);
return false;
}
return true;
} function getImgFullPath(obj) {
if (obj) {
//ie
if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
obj.select();
return document.selection.createRange().text;
}
//firefox
else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
if (obj.files) {
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}

2014-07-19 13:59:55

基于imgAreaSelect的用户图像截取的更多相关文章

  1. 基于AXI VDMA的图像采集系统

    基于AXI VDMA的图像采集系统 转载 2017年04月18日 17:26:43 标签: framebuffer / AXIS / AXI VDMA 2494 本课程将对Xilinx提供的一款IP核 ...

  2. 基于SURF特征的图像与视频拼接技术的研究和实现(一)

    基于SURF特征的图像与视频拼接技术的研究和实现(一)      一直有计划研究实时图像拼接,但是直到最近拜读西电2013年张亚娟的<基于SURF特征的图像与视频拼接技术的研究和实现>,条 ...

  3. 基于jwt的用户登录认证

    最近在app的开发过程中,做了一个基于token的用户登录认证,使用vue+node+mongoDB进行的开发,前来总结一下. token认证流程: 1:用户输入用户名和密码,进行登录操作,发送登录信 ...

  4. 基于RC4加密算法的图像加密

    基于RC4加密算法的图像加密 某课程的一个大作业内容,对图像加密.项目地址:https://gitee.com/jerry323/RC4_picture 这里使用的是RC4(流.对称)加密算法,算法流 ...

  5. Laravel 5 中使用 JWT(Json Web Token) 实现基于API的用户认证

    在JavaScript前端技术大行其道的今天,我们通常只需在后台构建API提供给前端调用,并且后端仅仅设计为给前端移动App调用.用户认证是Web应用的重要组成部分,基于API的用户认证有两个最佳解决 ...

  6. 基于jQuery点击图像居中放大插件Zoom

    分享一款基于jQuery点击图像居中放大插件Zoom是一款放大的时候会从原图像的位置以动画方式放大到画面中间,支持点击图像或者按ESC键来关闭效果.效果图如下: 在线预览   源码下载 实现的代码. ...

  7. 深度学习与计算机视觉(12)_tensorflow实现基于深度学习的图像补全

    深度学习与计算机视觉(12)_tensorflow实现基于深度学习的图像补全 原文地址:Image Completion with Deep Learning in TensorFlow by Bra ...

  8. 项目一:第十一天 2、运单waybill快速录入 3、权限demo演示-了解 5、权限模块数据模型 6、基于shiro实现用户认证-登录(重点)

    1. easyui DataGrid行编辑功能 2. 运单waybill快速录入 3. 权限demo演示-了解 4. Apache shiro安全框架概述 5. 权限模块数据模型 6. 基于shiro ...

  9. 基于稀疏表示的图像超分辨率《Image Super-Resolution Via Sparse Representation》

    由于最近正在做图像超分辨重建方面的研究,有幸看到了杨建超老师和马毅老师等大牛于2010年发表的一篇关于图像超分辨率的经典论文<ImageSuper-Resolution Via Sparse R ...

随机推荐

  1. Berkely DB Java Edition学习笔记

    Berkely DB对于高并发.要求速度快的应用来说是个不错的选择,mysql就是用BDB实现的(mysql的后台) ,mysql快,BDB比mysql还要快N倍.BDB是一种嵌入式的.非关系数据库, ...

  2. 【Android】SQLite基本用法(转)

    在Android开发中SQLite起着很重要的作用,网上SQLite的教程有很多很多,不过那些教程大多数都讲得不是很全面.本人总结了一些SQLite的常用的方法,借着论坛的大赛,跟大家分享分享的.一. ...

  3. yii框架美化访问路径,去掉index.php/?r=部分

    一.找到配置文件(ps:advance高级模板) 在工程目录-> backend目录 或 frontend目录 -> config目录 -> main.php文件 -> 在 r ...

  4. AC日记——集合位置 洛谷 P1491

    集合位置 思路: 次短路: 先走一遍最短路: 记录最短路径,然后依次删边走最短路: 最短的长度就是次短路: 来,上代码: #include <queue> #include <cma ...

  5. 语义分割丨PSPNet源码解析「训练阶段」

    引言 之前一段时间在参与语义分割的项目,最近有时间了,正好把这段时间的所学总结一下. 在代码上,语义分割的框架会比目标检测简单很多,但其中也涉及了很多细节.在这篇文章中,我以PSPNet为例,解读一下 ...

  6. openshift scc解析

    SCC使用UserID,FsGroupID以及supplemental group ID和SELinux label等策略,通过校验Pod定义的ID是否在有效范围内来限制pod的权限.如果校验失败,则 ...

  7. Topcoder SRM 668 DIV 2

    VerySecureEncryption 模拟 题意: 给你个串message,然后一个置换key,输出置换K次后的结果. 题解: 直接模拟就好. 代码: #include<iostream&g ...

  8. 你值得关注的几种常见的js设计模式

    前言 潜水了一段时间,今天空闲时间复盘下之前的知识点,聊聊 js 几种常见的设计模式. 掌握 JavaScript 中常见的一些设计模式,对我们书写规范性代码,可维护性代码有很大的帮助. ps:最近在 ...

  9. Git 详细的操作指南笔记

    喜欢的朋友start一下,长期更新文章 设置 安装git后我们需要配置一下,告诉git我们的基本信息等等..一般在用户范围内去配置 git ,也就是在 global 范围. global 全局设置 $ ...

  10. ci框架文件上传

    控制器类代码 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Upload ex ...