javascript - HTML5 图片上传,拖放、裁剪和比例
问题描述
我正在尝试使用带有拖放、裁剪和比率 JS 插件的 HTML5 图像上传。
我可以让它工作,只要让小部件在允许我放大和移动它的页面上运行等。但我坚持保存图像,有很多选项但没有示例。对于我可以收集的内容,它将数据发布到我可以使用以下数据作为示例定义的 URL。我假设我必须阅读并使用它将数据保存为 .jpg 图像?我是否按照正确的思路思考?
抱歉含糊不清,但我真的不知道从哪里开始或添加什么,因为我在这里是新的,但任何帮助将不胜感激。
我页面上的代码是:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HTML5 Image upload width drag and drop, crop and ratio</title>
<meta name="description" content="A HTML5 image upload plugin build with jQuery. Can drag and drop an image, crop it and change ratio." />
<!-- Bootstrap -->
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<link href="css/html5imageupload.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="row">
<div class="col-xs-6">
<div class="dropzone" data-width="960" data-height="540" data-ghost="false" data-canvas="false" data-smaller="true" data-canvas-image-only="true" data-originalsize="false" data-url="" data-resize="true" style="width: 100%;">
<input type="file" name="thumb" />
</div>
</div>
<div class="col-xs-6">
<a name="ghost"></a>
<h2>Ghosting & Original size</h2>
</div>
</div>
<hr />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="js/html5imageupload.js"></script>
<script>
$('#retrievingfilename').html5imageupload({
onAfterProcessImage: function() {
$('#filename').val($(this.element).data('name'));
},
onAfterCancel: function() {
$('#filename').val('');
}
});
$('#save').html5imageupload({
onSave: function(data) {
console.log(data);
},
});
$('.dropzone').html5imageupload();
$( "#myModal" ).on('shown.bs.modal', function(){
$('#modaldialog').html5imageupload();
});
/*
$('#form').html5imageupload({
onAfterProcessImage: function() {
$(this.element).closest('form').submit();
}
});
$('form button.btn').unbind('click').click(function(e) {
e.preventDefault()
$(this).closest('form').find('#form').data('html5imageupload').imageCrop()
});*/
</script>
</body>
</html>
如果我是正确的,它发布的一个例子是: -
The $_POST variable
array(3) {
["name"]=>
string(2) "fg"
["title"]=>
string(2) "fg"
["thumb_values"]=>
string(112422) "{"data":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA==","name":"logo.png","imageOriginalWidth":225,"imageOriginalHeight":44,"imageWidth":2762,"imageHeight":540,"width":960,"height":540,"left":-901,"top":0}"
}
The JSON object
object(stdClass)#1 (10) {
["data"]=>
string(112262) "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA=="
["name"]=>
string(8) "logo.png"
["imageOriginalWidth"]=>
int(225)
["imageOriginalHeight"]=>
int(44)
["imageWidth"]=>
int(2762)
["imageHeight"]=>
int(540)
["width"]=>
int(960)
["height"]=>
int(540)
["left"]=>
int(-901)
["top"]=>
int(0)
}
解决方案
推荐阅读
- html - 为什么一个ul比另一个低
- c - 为什么函数总是返回 0?(C)
- ios - 打开具有视频类型的 PhotoLibrary,无需压缩过程
- openstreetmap - 创建一个移动标记。机器人操作系统(ROS)
- android - android中的kotlin:删除意图的对象值,因为它只使用一次
- python - 'Final' 语句在递归函数中执行两次 [Python 3.6]p
- delphi - 如何将文本从 Indy TCPServer 发送到 TCPClient
- android - 活动轮换释放
- mysql - 提取计算的 JSONpath 响应的第一个元素
- f# - 如何在 F# 交互中使用 Span?