gpt4 book ai didi

javascript - 如何使用 plupload 保存两个不同尺寸的图像

转载 作者:行者123 更新时间:2023-11-30 18:38:54 24 4
gpt4 key购买 nike

我正在使用 Plupload 插件上传多张图片,因为我们可以选择在客户端调整图片大小,我想上传原始大小的图片并将它们保存到单独的文件夹,并将调整后的图片保存到另一个文件夹。

任何人都可以建议我如何进一步进行吗?这是我的代码:

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim chunk As Integer = If(context.Request("chunk") IsNot Nothing, Integer.Parse(context.Request("chunk")), 0)
Dim fileName As String = If(context.Request("name") IsNot Nothing, context.Request("name"), String.Empty)

Dim fileUpload As HttpPostedFile = context.Request.Files(0)

Dim uploadPath = context.Server.MapPath("~/uploads")
Using fs = New FileStream(Path.Combine(uploadPath, fileName), If(chunk = 0, FileMode.Create, FileMode.Append))
Dim buffer = New Byte(fileUpload.InputStream.Length - 1) {}
fileUpload.InputStream.Read(buffer, 0, buffer.Length)

fs.Write(buffer, 0, buffer.Length)
End Using

context.Response.ContentType = "text/plain"
context.Response.Write("Success")
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property

这是我的脚本代码:

<script type="text/javascript">
$(function () {
// Setup flash version
$("#flash_uploader").pluploadQueue({
// General settings
runtimes: 'flash',
url: 'upload.ashx',
max_file_size: '10mb',
chunk_size: '1mb',
unique_names: true,
filters: [
{ title: "Image files", extensions: "jpg" }
],

// Resize images on clientside if we can
resize: { width: 800, height: 600, quality: 90 },

// Flash settings
flash_swf_url: 'js/plupload.flash.swf',

init: { StateChanged: function (up) {
// Called when the state of the queue is changed
if (up.state == plupload.STOPPED) {
$("#btnSubmit").removeAttr("disabled");
}
}
}

});
var uploader = $('#flash_uploader').pluploadQueue();
uploader.bind('FileUploaded', function (up, file, res) {
$('#showfilelist').append("<div id=" + file.id + "><a href='uploads/" + file.target_name + "' target='_blank'><img src='uploads/" + file.target_name + "' border='0'/><br>" + file.name + "</a><br>(" + plupload.formatSize(file.size) + ") <span></span></div>");

});
});

</script>

最佳答案

// Resizing an image
// Inputs [ new image size (Height,Width), Origial file path & name, new file path & name ]

ResizeImage(int height,int width, string inputFile, string outputFile)
{
var img = Image.FromFile(inputFile);
Image imagThumb = null;
imagThumb = img.GetThumbnailImage(width, height, null, new IntPtr());
imagThumb.Save(outputFile);
}

可以从保存图像的路径访问输入和输出文件

eg.var input = Server.MapPath("~/images/imagename");

关于javascript - 如何使用 plupload 保存两个不同尺寸的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7446208/

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