We are trying to generate image gallery thumbnail images programmatically in our ASP.NET MVC3 website instead of doing this manually all the times.
我们正在尝试在ASP.NET MVC3网站中以编程方式生成图库缩略图图像,而不是一直手动执行此操作。
We are looking for implementing a function that checks in the TEMP folder is the thumbnail is present, otherwise creates and uses it.
我们正在寻找实现一个函数,检查TEMP文件夹中是否存在缩略图,否则创建并使用它。
Is a controller action the right place to implement this? What should this action return?
控制器动作是否适合实施此操作?这个动作应该返回什么?
We already implemented the image generation on the fly with several problems when many thumbnail images are on the gallery page (some are always missing, because of too many hits?) and we'd like to try a different approach.
我们已经实现了动画中的图像生成,当画廊页面上有许多缩略图时有些问题(由于点击次数太多,有些总是丢失?)我们想尝试不同的方法。
Thanks.
谢谢。
3 个解决方案
#1
1
I would advise you not to create image/thumbnail generator yourself , but rather use http://imageresizing.net a C# library that has many advanced functions and plugins ( cahcing , creating thumbnails , dynamic resizing, etc, etc.)
我建议你不要自己创建图像/缩略图生成器,而是使用http://imageresizing.net一个C#库,它有许多高级函数和插件(cahcing,创建缩略图,动态调整大小等等)
Here is the NuGet url : http://nuget.org/packages/ImageResizer/
这是NuGet网址:http://nuget.org/packages/ImageResizer/
Here is a sample config i use
这是我使用的示例配置
<resizer>
<plugins>
<add name="MvcRoutingShim" />
<add name="DiskCache" />
</plugins>
<diskCache dir="~/imagecache" autoClean="false" hashModifiedDate="true" enabled="true" subfolders="32" cacheAccessTimeout="3000" asyncWrites="false" asyncBufferSize="10485760" />
<clientcache minutes="7200" />
</resizer>
#2
0
I would do such processing in a separate process, preferably Windows Service.
我会在一个单独的过程中进行这样的处理,最好是Windows服务。
AppDomain can be recycled by IIS and your thumbnail processing thread may be killed in the middle of work. The same applies when the new version of the website is deployed or configuration changed.
IIS可以回收AppDomain,您的缩略图处理线程可能会在工作中被杀死。当部署新版本的网站或更改配置时,同样适用。
Monitoring and maintenance of the background thread in IIS worker process would be probably more difficult than a separate Windows Service.
在IIS工作进程中监视和维护后台线程可能比单独的Windows服务更难。
#3
0
Personally, I would create an ImageThumbnailService
or similar and expose it to your web app through an appropriate interface. That way, your application need only ask the service for a thumbnail and the service can do the worrying about whether or not the file exists, etc., calling off to some other class to create the thumbnail if it doesn't.
就个人而言,我会创建一个ImageThumbnailService或类似的,并通过适当的界面将其公开给您的Web应用程序。这样,您的应用程序只需要向服务询问缩略图,并且服务可以担心文件是否存在等,如果不存在,则调用其他类来创建缩略图。
#1
1
I would advise you not to create image/thumbnail generator yourself , but rather use http://imageresizing.net a C# library that has many advanced functions and plugins ( cahcing , creating thumbnails , dynamic resizing, etc, etc.)
我建议你不要自己创建图像/缩略图生成器,而是使用http://imageresizing.net一个C#库,它有许多高级函数和插件(cahcing,创建缩略图,动态调整大小等等)
Here is the NuGet url : http://nuget.org/packages/ImageResizer/
这是NuGet网址:http://nuget.org/packages/ImageResizer/
Here is a sample config i use
这是我使用的示例配置
<resizer>
<plugins>
<add name="MvcRoutingShim" />
<add name="DiskCache" />
</plugins>
<diskCache dir="~/imagecache" autoClean="false" hashModifiedDate="true" enabled="true" subfolders="32" cacheAccessTimeout="3000" asyncWrites="false" asyncBufferSize="10485760" />
<clientcache minutes="7200" />
</resizer>
#2
0
I would do such processing in a separate process, preferably Windows Service.
我会在一个单独的过程中进行这样的处理,最好是Windows服务。
AppDomain can be recycled by IIS and your thumbnail processing thread may be killed in the middle of work. The same applies when the new version of the website is deployed or configuration changed.
IIS可以回收AppDomain,您的缩略图处理线程可能会在工作中被杀死。当部署新版本的网站或更改配置时,同样适用。
Monitoring and maintenance of the background thread in IIS worker process would be probably more difficult than a separate Windows Service.
在IIS工作进程中监视和维护后台线程可能比单独的Windows服务更难。
#3
0
Personally, I would create an ImageThumbnailService
or similar and expose it to your web app through an appropriate interface. That way, your application need only ask the service for a thumbnail and the service can do the worrying about whether or not the file exists, etc., calling off to some other class to create the thumbnail if it doesn't.
就个人而言,我会创建一个ImageThumbnailService或类似的,并通过适当的界面将其公开给您的Web应用程序。这样,您的应用程序只需要向服务询问缩略图,并且服务可以担心文件是否存在等,如果不存在,则调用其他类来创建缩略图。