gpt4 book ai didi

javascript - 我们如何在 imgareaselect 中显示选定区域

转载 作者:行者123 更新时间:2023-11-28 08:39:58 24 4
gpt4 key购买 nike

代码是:

    <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery UI Tooltip - Default functionality</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 src="http://deepliquid.com/projects/Jcrop/js/jquery.min.js"></script>
<script src="http://deepliquid.com/projects/Jcrop/js/jquery.Jcrop.js"></script>
<link rel="stylesheet" href="http://deepliquid.com/projects/Jcrop/css/jquery.Jcrop.css" type="text/css" />
<link rel="stylesheet" href="http://deepliquid.com/projects/Jcrop/demos/demo_files/demos.css" type="text/css" />

<link rel="stylesheet" href="/resources/demos/style.css">
<script >
$(function () {
function readImage(file) {

var reader = new FileReader();
var image = new Image();
var maxw = 600;
var maxh = 600;

reader.readAsDataURL(file);
reader.onload = function (_file) {
image.src = _file.target.result; // url.createObjectURL(file);
image.onload = function () {
var w = this.width,
h = this.height,
t = file.type, // ext only: // file.type.split('/')[1],
n = file.name,
s = ~~ (file.size / 1024) + 'KB';
if ( h > maxh || w > maxw) {
alert("Height and width is bigger then over max criteria pls select image max height and width =2024X2024");
alert(w);
alert(h);
} else {
alert(w);
alert(h);
$('#uploadPreview').html('<img id="myImage" src="' + this.src + '"> ' + w + 'x' + h + ' ' + s + ' ' + t + ' ' + n + '<br>');
$('#myImage').Jcrop({
onChange: showPreview,
onSelect: showPreview,
aspectRatio: 1
});
}

};
image.onerror = function () {
alert('Invalid file type: ' + file.type);
};
};

}

$("#choose").change(function (e) {
if (this.disabled) return alert('File upload not supported!');
var F = this.files;
if (F && F[0]) for (var i = 0; i < F.length; i++) readImage(F[i]);
});

var thumbWidth = 145, thumbHeight = 190;
<!--$(function(){ $('#jcrop_target').Jcrop(); });-->
function showPreview(coords)
{
var rx = thumbWidth / coords.width;
var ry = thumbHeight / coords.height;

$('#uploadPreview1 + div > img').css({
width: Math.round(rx * $("#uploadPreview1").width()) + 'px',
height: Math.round(ry * $("#uploadPreview1").height()) + 'px',
marginLeft: '-' + Math.round(rx * coords.width) + 'px',
marginTop: '-' + Math.round(ry * coords.height) + 'px'
});
}
$('<div id=""> <img src=\"" + image + "\" \/><div> ')
.css({
float: 'right',
position: 'relative',
overflow: 'hidden',
width: thumbWidth + 'px',
height: thumbHeight + 'px'
})
.insertAfter($('#uploadPreview1'));



});




</script>



<style>



</style>
</head>
<body >
<input type="file" id="choose" multiple="multiple" />
<br>
<div id="uploadPreview" ></div><br>

<div id="" ><img src="" /></div><br>

</body>
</html>

首先,我上传图像,然后检查图像的最低标准。

如果图像通过标准,那么我会将其显示在页面上。然后我选择一个区域来创建缩略图。

但是,当我选择图像的某个区域时,我无法在新的 div 中显示所选区域。

一切正常。但无法显示所选区域。我的代码中的问题是(如何将图像的 src 传递给 img 标签或 div 标签)

希望你能理解这个问题。

最佳答案

divHtml=$('<div/>',{'id':ANYID}).css({
float: 'right',
position: 'relative',
overflow: 'hidden',
width: thumbWidth + 'px',
height: thumbHeight + 'px'
});
imgHtml=$('<img/>',{'src':IMGSRCPATH, 'alt':ALTVALUE, 'title':TITLEVALUE});

var appendVal = divHtml.append(imgHtml).insertAfter($('#uploadPreview'));

请尝试这个。

关于javascript - 我们如何在 imgareaselect 中显示选定区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20626944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com