简体   繁体   English

显示文章中图像的缩略图

[英]Display thumbnails for images in articles

So I have this website where users can post articles, each article containing at least one photo. 所以我有这个网站,用户可以发布文章,每篇文章至少包含一张照片。 What I want to do is when I display the list of articles on the website I want to also show a thumbnail next to the articles name. 我想要做的是当我在网站上显示文章列表时,我还要在文章名称旁边显示缩略图。

Here comes the tricky part: the images are not hosted on my server, are simply links hosted on some image-hosting website. 这里有一个棘手的部分:图像不是托管在我的服务器上,只是托管在一些图像托管网站上的链接。 Another problem is that I don't know where the images appear in the post (they could be at the beginning, at the end or in the middle of the article). 另一个问题是我不知道图像在帖子中出现的位置(它们可能位于文章的开头,结尾或中间)。

What would be the best approach to create a thumbnail system in this case? 在这种情况下,创建缩略图系统的最佳方法是什么?

I was thinking maybe I could do this: every time an article is posted or edited and stored into the database I could scan the entire articles for images links and store the first link in a separate value in the database (this could be kind of slow though). 我想也许我可以这样做:每次发布或编辑文章并存储到数据库中时,我都可以扫描整篇文章中的图像链接,并将第一个链接存储在数据库中的单独值中(这可能有点慢虽然)。 Also once I have those values stored and I have to display a thumbnail the only way to do so will be by showing the full image resized to the thumbnail size (that means the user has to download multiple full-size images to see the articles list with thumbnails). 此外,一旦我存储了这些值并且我必须显示缩略图,唯一的方法是通过显示调整大小缩放到缩略图大小的完整图像(这意味着用户必须下载多个全尺寸图像才能看到文章列表用缩略图)。

Is there any better approach? 有没有更好的方法? (you can see the technologies used in the tags) (你可以看到标签中使用的技术)

  • Use HtmlAgilityPack as a starter to get to the images from the image host. 使用HtmlAgilityPack作为启动程序从图像主机获取图像。
  • Use an ASP.NET handler to generate the thumbnails. 使用ASP.NET处理程序生成缩略图。 That way, you won't have to store anything locally, the thumbnails images will only exist in memory, making hotlinking impossible 这样,您就不必在本地存储任何内容,缩略图图像只会存在于内存中,从而无法进行热链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM