有没有办法缩小图像的大小,这样加载时间就不会严重陷入困境

发布于 2024-11-26 05:28:27 字数 241 浏览 2 评论 0原文

我正在编写一个画廊应用程序,该应用程序从 rss 提要中提取图像,因此无法直接编辑图像。

不幸的是,一些画廊非常大,因为文件是大规模上传的。

有没有办法确保图像加载时使用 javascript/jquery 以合理的大小加载?

感谢您一如既往的帮助!

哦还有 - 如果我将这些图像直接从 RSS 链接到它们源自的网站,比如说 - 谷歌 RSS 提要,这会给我带来任何麻烦吗?他们从他们的网站加载一堆图像?

I'm writing a gallery application that pulls images from an rss feed, so editing the images directly isn't an option.

Unfortunately some of the galleries are quite large because the files were uploaded as a large scale.

Is there a way to make sure when the images are loaded to have them load at a reasonable size with javascript/jquery?

Thanks for your help as always!

Oh also- if im linking these images directly from the rss to the site they originated from, say- a google rss feed, can that land me in any trouble with them loading a bunch of images off their site?

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

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

发布评论

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

评论(6

审判长 2024-12-03 05:28:27

仅使用 javascript / jquery,不行。

假设无法将图像存储在服务器上,则必须使用服务器端脚本(例如 php)将图像加载到服务器上,缩小图像并将其传送到浏览器。

因此,您的客户端脚本将类似于

$("#myImgTag").attr( 'src', 'http://yourserver.com/getRSSimage.php?url=google.com/rss/reallyBigImage' );

至于直接链接的合法性,它是一个合法的灰色区域。如果你试图声明这些图像是你的,那么是的,这是非法的,但是,清楚地显示图像的来源并给予所有必要的信用,这被认为是可以的,特别是如果你不从中赚钱。

With just javascript / jquery, no.

Assuming that storing the images on your server isn't an option, you would have to use a server side script like php to load the image on your server, scale it down and deliver that to the browser.

So your client side script would be something like

$("#myImgTag").attr( 'src', 'http://yourserver.com/getRSSimage.php?url=google.com/rss/reallyBigImage' );

As to the legality of linking directly, its a legal gray area. If you try to state that the images are yours, then yes its illegal, however, clearly showing where the images came from giving all necessarily credit, that's considered ok especially if you're not making money from it.

琉璃梦幻 2024-12-03 05:28:27

有没有办法确保图像何时加载以获取它们
使用 javascript/jquery 以合理的大小加载?

如果我将这些图像直接从 rss 链接到他们的网站
比如说,源自谷歌的 RSS 提要,这能让我进入任何
他们从网站上加载一堆图像时遇到麻烦吗?

是的

Is there a way to make sure when the images are loaded to have them
load at a reasonable size with javascript/jquery?

No

if im linking these images directly from the rss to the site they
originated from, say- a google rss feed, can that land me in any
trouble with them loading a bunch of images off their site?

Yes

明月夜 2024-12-03 05:28:27

您要求的是服务器端操作。客户端浏览器中的 jQuery 只能在浏览器接收到图像后才能对其进行操作。要下载较小的图像,您需要:

1) 了解如何从网站请求较小的图像而不是较大的图像。例如,如果 RSS 源来自 Smugmug 等照片网站,则可以修改图像 URL 以请求更小的尺寸。

2) 修改服务器以支持较小大小的请求(我认为这不适合您)。

你正在做的事情是否会给你带来麻烦取决于你正在做的事情的更多细节。网络上包含公共图像和公共 RSS 源的网站允许对这些内容进行合理使用,但不允许出于任何目的无限制地使用。我们必须了解更多细节。

What you are asking for would be server-side operation. jQuery in the client browser can only operate on the images after they have been received in the browser. To download smaller images, you would need to either:

1) Learn how to request smaller images from the site rather than the larger sizes. For example, if the RSS feed was from a photo site like Smugmug, the image URLs can be modified to request a smaller size.

2) Modify the server to support a request for a smaller size (I presume this is not an option for you).

Whether what you are doing will get you into trouble depends on more of the details of what you are doing. A site on the web with public images and a public RSS feed is allowing some fair use of those, but is not allowing unlimited use for any purpose. We would have to know a lot more specifics.

橘香 2024-12-03 05:28:27

简短的回答:不,不是。即使从逻辑上讲,这种转变也必须发生在某个地方,而且你必须对原始的进行这种转变。既然如此,因为无论如何你都必须加载原始文件,所以没有必要重新调整它的大小。至于热链接,我不认为这是非法的,但是您进行热链接的网站会因此讨厌您。

Short answer: no not really. even logically, such transformation has to occur somewhere, and you have to do so to the original. That being the case, since you have to load the original anyway, there is no point to re-sizing it. And as for hotlinking, I don't think it's illegal, but the site that you are hotlinking from will hate you for it.

心是晴朗的。 2024-12-03 05:28:27

如果图库始终使用相同的 RSS 提要,您可以考虑缩放图像并将其存储在服务器上。当用户访问您的图库时,可以简单地检查“缩略图”图像是否可用并加载该图像。这需要一点 JavaScript/AJAX,并且您必须编写一些代码来缩放和存储图像。

但这确实并不理想。缩放和存储图像需要大量处理器和内存。如果您要为大量用户和大量图像提供服务,那么这将无法很好地扩展。我不认为你从服务器上提取大量图像有任何问题......这就是它们的用途,对吧?只需确保您的请求不会浪费并尊重服务器的带宽即可。

If the gallery always uses the same RSS feed, you could look into scaling and storing the images on the server. When a user visits your gallery, a simple check could be made for whether the "thumbnail" image is available and to load that one instead. That would require a little JavaScript / AJAX, and you'd have to write some code to scale and store images.

This really isn't ideal though. Scaling and storing images is both processor and memory intensive. If you're serving lots of users and lots of images, this isn't going to scale well. I don't see any problem with you pulling lots of images from a server... that's what they're there for right? Just make sure you're not being wasteful with your requests and respecting the bandwidth of the server.

千年*琉璃梦 2024-12-03 05:28:27

其他答案是正确的,因为图像优化需要在服务器端完成。然而,有一些工具可以为您完成这项工作,这些工具使您只需修改通过 JS 分配的图像 src 即可提供优化的图像。

请查看 http://www.punypng.com/api 示例。

但请注意,这并不理想,因为您依赖外部服务器的资源等来提供图像。

The other answers are correct in that the image optimization would need to be done server-side. There are some tools that can do this work for you, however, which would enable you to serve optimized images just by modifying the image src that you're assigning through JS.

Take a look at http://www.punypng.com/api for an example.

Take note that this isn't ideal, though, since you're relying on the resources/etc of an outside server to serve images.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文