上传照片

发布于 2024-11-07 14:17:42 字数 348 浏览 0 评论 0原文

我的问题是关于将照片上传到网络服务器。

我最近在 Facebook 上上传照片时观察到,它可以上传(默认情况下确实如此)上传比我们要求的更小的照片。

现在,我可以考虑上传全尺寸照片并在到达服务器时进行压缩。

但是 facebook 如何在上传时调整图片大小。
是否有任何请求标头(我认为没有)要求浏览器上传特定尺寸的图像并操作文件中的 exif/jpeg 数据。

如果没有,某些插件/Flash/Javascript 必须读取来自我们系统的文件/图像。 网络标准真的允许从用户系统读取文件吗?

请指教。

问候,
玛雅克

My question is regarding uploading photographs to a webserver.

I recently observed while uploading a photograph on facebook that it can upload (and by default it does) upload smaller photographs than what we request.

Now, I can think of uploading a full size photograph and compress when it reaches the server.

But how could facebook resize the picture while uploading.
Is there any request header (I think there is not) that asks browser to upload specific size image and manipulate the exif/jpeg data in the file.

If not, some plugin/Flash/Javascript has to read the file/images from our system. Does web standard really allow file reading from the user system?

Please advise.

Regards,
Mayank

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄与心 2024-11-14 14:17:42

在上传并保存到目标目录之前,网站/网络服务器无法对图像执行任何操作。它必须接收全尺寸图像,然后将其重新定位到所需尺寸[生成缩略图等]。没有您描述的请求标头。

Web 标准不允许从用户硬盘读取文件。他们允许的事情是从硬盘中选择文件然后发送到服务器 - 主动权在客户端,而不是服务器。

您还有什么想了解的吗?

更新

请参阅:Flash 上传图像调整大小客户端

正如我所说 - 没有外部机制我们什么也做不了。但当然,如果我们考虑到 Flash、Google Gears 等,一切皆有可能。

Website / webserver cannot do anything with the image until it is uploaded and saved into target directory. It must receive fullsize image and then resite it to desired size [generate thumbnails, etc.]. There is no request header that you described.

Web standards don't allow reading files from user hard disk. The thing that they allow is to select file from hard disk and then send to server - initiative is on the client's side, not server's.

Is there anything more you would like to know?

update

See this: Flash upload image resize client side

As I said - without external mechanisms we can't do anything. But of course, if we take into account Flash, Google Gears and so on, everything is possible.

初吻给了烟 2024-11-14 14:17:42

现在 HTML5 已成为可能

目前并非所有浏览器都支持它,但是 HTML5 中的某些功能可以在通过网络发送图像之前调整图像大小。

看看 hacks.mozilla.org...了解更多详情

摘自上述链接:

调整图像大小

人们习惯上传图片
直接从他们的相机拍摄。这给出了
高分辨率且极重
(几兆字节)文件。根据
的用法,你可能想调整这样的大小
图像。一个超级简单的技巧是
只需有一个小画布(800×600
例如)并绘制图像标签
进入这个画布。当然,你会
必须更新画布尺寸
保持图像的比例。

var MAX_WIDTH = 800;
var MAX_HEIGHT = 600;
var width = img.width;
var height = img.height;

if (width > height) {
  if (width > MAX_WIDTH) {
    height *= MAX_WIDTH / width;
    width = MAX_WIDTH;
  }
} else {
  if (height > MAX_HEIGHT) {
    width *= MAX_HEIGHT / height;
    height = MAX_HEIGHT;
  }
}
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height)

It is now possible with HTML5

Not all browsers accommodate it at the present however there are some features in HTML5 that will resize an image before it sends it over the wire.

Look at hacks.mozilla.org... for more details

Excerpt from the above link:

Resize the Image

People are used to uploading images
straight from their camera. This gives
high resolution and extremely heavy
(several megabyte) files. Depending on
the usage, you may want to resize such
images. A super easy trick is to
simply have a small canvas (800×600
for example) and to draw the image tag
into this canvas. Of course, you’ll
have to update the canvas dimensions
to keep the ratio of the image.

var MAX_WIDTH = 800;
var MAX_HEIGHT = 600;
var width = img.width;
var height = img.height;

if (width > height) {
  if (width > MAX_WIDTH) {
    height *= MAX_WIDTH / width;
    width = MAX_WIDTH;
  }
} else {
  if (height > MAX_HEIGHT) {
    width *= MAX_HEIGHT / height;
    height = MAX_HEIGHT;
  }
}
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文