/**
* jquery.Jcrop.js v0.9.5
* jQuery Image Cropping Plugin
* @author Kelly Hallman <khallman@wrack.org>
* Copyright (c) 2008 Kelly Hallman - released under MIT License {{{
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
* }}}
*/
$.Jcrop = function(obj, opt) {
// Initialization {{{
// Sanitize some options {{{
var obj = obj, opt = opt;
if (typeof(obj) !== 'object') obj = $(obj)[0];
if (typeof(opt) !== 'object') opt = { };
if (!('trackDocument' in opt))
opt.trackDocument = $.browser.msie ? false : true;
if (!('keySupport' in opt))
opt.keySupport = $.browser.msie ? false : true;
// }}}
// Extend the default options {{{
var defaults = {
// Basic Settings
trackDocument: false,
baseClass: 'jcrop',
addClass: null,
// Styling Options
bgColor: 'black',
bgOpacity: .6,
borderOpacity: .4,
handleOpacity: .5,
handlePad: 5,
handleSize: 9,
handleOffset: 5,
edgeMargin: 14,
aspectRatio: 0,
keySupport: true,
cornerHandles: true,
sideHandles: true,
drawBorders: true,
dragEdges: true,
boxWidth: 0,
boxHeight: 0,
boundary: 8,
animationDelay: 20,
swingSpeed: 3,
watchShift: false,
minSelect: [0, 0],
maxSize: [0, 0],
minSize: [0, 0],
// Callbacks / Event Handlers
onChange: function() {
},
onSelect: function() {
}
};
var options = defaults;
setOptions(opt);
// }}}
// Initialize some jQuery objects {{{
var $img = $(obj).css({ position: 'absolute' });
presize($img, options.boxWidth, options.boxHeight);
var boundx = $img.width(),
boundy = $img.height(),
$div = $('<div />')
.width(boundx).height(boundy)
.addClass(cssClass('holder'))
.css({
position: 'relative',
//overflow: 'hidden',
backgroundColor: options.bgColor
});
if (options.addClass) $div.addClass(options.addClass);
$img.wrap($div);
var $img2 = $('<img />')/*{{{*/
.attr('src', $img.attr('src'))
.css('position', 'absolute')
.width(boundx).height(boundy); /*}}}*/
var $img_holder = $('<div />')/*{{{*/
.width(pct(100)).height(pct(100))
.css({
zIndex: 310,
position: 'absolute',
overflow: 'hidden'
})
.append($img2); /*}}}*/
var $hdl_holder = $('<div />')/*{{{*/
.width(pct(100)).height(pct(100))
.css({
zIndex: 320
//position: 'absolute'
}); /*}}}*/
var $sel = $('<div />')/*{{{*/
.css({
position: 'absolute',
zIndex: 300
})
.insertBefore($img)
.append($img_holder, $hdl_holder); /*}}}*/
var bound = options.boundary;
var $trk = $('<div />')
.addClass(cssClass('tracker'))
.width(boundx + (bound * 2))
.height(boundy + (bound * 2))
.css({
position: 'absolute',
top: px(-bound),
left: px(-bound),
zIndex: 290,
opacity: 0
})
.mousedown(newSelection);
/* }}} */
// Set more variables {{{
var xscale, yscale;
var docOffset = getPos(obj),
// Internal states
btndown, aspectLock, lastcurs, dimmed, animating,
shift_down;
// }}}
if ('trueSize' in options)/*{{{*/ {
xscale = options.trueSize[0] / boundx;
yscale = options.trueSize[1] / boundy;
}
/*}}}*/
// }}}
// Internal Modules {{{
var Coords = function()/*{{{*/
{
var x1 = 0, y1 = 0, x2 = 0, y2 = 0, ox, oy;
function setPressed(pos)/*{{{*/
{
var pos = rebound(pos);
x2 = x1 = pos[0];
y2 = y1 = pos[1];
}
;
/*}}}*/
function setCurrent(pos)/*{{{*/
{
var pos = rebound(pos);
ox = pos[0] - x2;
oy = pos[1] - y2;
x2 = pos[0];
y2 = pos[1];
}
;
/*}}}*/
function getOffset()/*{{{*/
{
return [ox, oy];
}
;
/*}}}*/
function moveOffset(offset)/*{{{*/
{
var ox = offset[0], oy = offset[1];
if (0 > x1 + ox) ox -= ox + x1;
if (0 > y1 + oy) oy -= oy + y1;
if (boundy < y2 + oy) oy += boundy - (y2 + oy);
if (boundx < x2 + ox) ox += boundx - (x2 + ox);
x1 += ox;
x2 += ox;
y1 += oy;
y2 += oy;
}
;
/*}}}*/
function getCorner(ord)/*{{{*/
{
var c = getFixed();
switch (ord) {
case 'ne':
return [c.x2, c.y];
case 'nw':
return [c.x, c.y];
case 'se':
return [c.x2, c.y2];
case 'sw':
return [c.x, c.y2];
}
}
;
/*}}}*/
function getFixed()/*{{{*/
{
if (!options.aspectRatio && !aspectLock) return getRect();
// This function could use some optimization I think...
var aspect = options.aspectRatio ? options.aspectRatio : aspectLock,
min = options.minSize,
max = options.maxSize,
rw = x2 - x1,
rh = y2 - y1,
rwa = Math.abs(rw),
rha = Math.abs(rh),
real_ratio = rwa / rha,
xx, yy;
if (real_ratio < aspect) {
yy = y2;
w = rha * aspect;
xx = rw < 0 ? x1 - w : w + x1;
if (xx < 0) {
xx = 0;
h = Math.abs((xx - x1) / aspect);
yy = rh < 0 ? y1 - h : h + y1;
} else if (xx > boundx) {
xx = boundx;
h = Math.abs((xx - x1) / aspect);
yy = rh < 0 ? y1 - h : h + y1;
}
} else {
xx = x2;
h = rwa / aspect;
yy = rh < 0 ? y1 - h : y1 + h;
if (yy < 0) {
yy = 0;
w = Math.abs((yy - y1) * aspect);
xx = rw < 0 ? x1 - w : w + x1;
} else if (yy > boundy) {
yy = boundy;
w = Math.abs(yy - y1) * aspect;
xx = rw < 0 ? x1 - w : w + x1;
}
C# ASP.NET - 图片在线裁剪
5星 · 超过95%的资源 需积分: 10 138 浏览量
2012-03-08
14:55:48
上传
评论
收藏 240KB 7Z 举报
GATTACA2011
- 粉丝: 313
- 资源: 1997
最新资源
- VSc++编程助手1.0 - 1
- 基于matlab的说话人语音识别源码+PPT+报告(优质项目).zip
- 语音识别基于matlab说话人识别系统源码+报告PPT(高分优质项目).zip
- 毕业设计: 校园失物招领小程序的设计与实现论文(源码 + 数据库 + 说明文档)
- 美易ME-DUI自绘模块3.3-易语言模块
- 毕业设计:小程序消防知识每天学(源码 + 数据库 + 说明文档)
- 2024-NEW.zip
- 软件.zip
- 华为FPGA设计技巧FPGA设计规范设计经验设计流程指南华为面经硬件工程师手册等资料(15个).zip
- 毕业设计:基于微信小程序大学校园二手教材与书籍拍卖系统(源码 + 数据库 + 说明文档)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页