在 ASP.NET 中本地化图像
几年前,我们请了一位平面设计师改造了我们的网站。 他的结果看起来很棒,但不幸的是他引入了一种网络浏览器不支持的新字体。
起初我想,“什么!?!”...因为我们的大部分内容都是动态的,并且没有真正的方法来预先制作所有图像。 还有多种语言的问题(因为我们知道西班牙语即将出现)。
不管怎样,我决定创建一些类来通过 GDI+ 自动生成图像,并根据需要以编程方式缓存它们。 这解决了我们最初的大部分问题。 然而,现在我们的负载急剧增加,UI 服务器出现了消耗。
现在的问题是...我希望用标准的网络浏览器字体替换大部分动态 GDI+ 图像。 我正在考虑保留一些渲染的 GDI+ 图像并将它们放入 resx 文件中,但计划通过 asp:Labels 将其中大部分替换为 Tahoma 或 Arial 字体。
您发现哪个是更好的本地化图像解决方案?
- 将图像嵌入到 resx 中
- 仅将图像 url 添加到 resx 中
- 其他一些解决方案
我主要关心的是限制 UI 服务器上的处理。 如果是这种情况,与实际将图像嵌入到 resx 相比,将图像 url 添加到 resx 是否是更好的解决方案?
A couple of years ago, we had a graphic designer revamp our website. His results looked great, but he unfortunately introduced a new unsupported font by the web browser.
At first I was like, "What!?!"... since most of our content is dynamic and there was no real way to pre-make all of the images. There was also the issue of multiple languages (since we knew Spanish was on the horizon).
Anyway, I decided to create some classes to auto-generate images via GDI+ and programatically cache them as needed. This solved most of our initial problems. However, now that our load has increased dramatically, there has been a drain on our UI server.
Now to the question... I am looking to replace most of the dynamic GDI+ images with a standard web browser font. I am thinking of keeping some of the rendered GDI+ images and putting them in a resx file, but plan to replace most of them with Tahoma or Arial fonts via asp:Labels.
Which have you found to be a better localized image solution?
- Embedding images into the resx
- Only adding the image url into the resx
- Some other solution
My main concern is to limit the processing on the UI server. If that is the case, would adding the image url to the resx be a better solution compared to actually embedding the image into the resx?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您应该只需要生成每个图像一次,然后将其保存在硬盘上。 您网站上的负载不应增加您必须执行的处理量。 话虽这么说,听起来好像您正在将图像用于不应该做的事情。 如果有太多不同的图像以至于您无法跟上生成它们的速度,那么是时候放弃您的精美图像而转而使用不应该是图像的东西,并返回到直接的文本。 如果用户没有安装指定的字体,它应该回退到类似的字体。 CSS对此有很好的支持。
You should only need to generate each image once, and then save it on the hard disk. The load on your site shouldn't increase the amount of processing you have to do. That being said, it almost sounds like you are using images for things you shouldn't be. If there are so many different images that you can't keep up with generating them, it's time to abandon your fancy images for things that shouldn't be images, and go back to straight text. If the user doesn't have the specified font installed, it should just fall back to a similar looking font. CSS has good support for this.
请参阅我的回复此处
这可以手动完成或使用某种自动化(CMS)系统。
基本方法是将图像缓存在特定于语言的目录结构中,然后编写一个 HTTP 处理程序来有效地删除附加目录层。 例如:
在您的标记或 CSS 中,您只需引用 /images/header1.gif。 然后,http 处理程序使用会话(如果语言是特定于用户的)或配置(如果是特定于站点的)来选择从哪个目录提供图像。
这在代码和内容之间提供了一条清晰的界限,并允许客户端缓存。 Resx 非常适合小字符串,但我更喜欢这样的系统来处理图像和较大的内容。 尤其是在网络上,通常很容易切换图像。
see my response here
This can be done manually or using some sort of automated (CMS) system.
The basic method is to cache your images in a language specific directory structure and then write an HTTP handler that effectively removes the additional directory layer. eg:
In your markup or CSS you would just reference /images/header1.gif. The http hander then uses session (if language is user specific), or config (if site specific) to choose which directory to serve the image from.
This provides a clean line bewteen code and content, and allows for client side caching. Resx is great for small strings but I much prefer a system like this for images and larger content. especially on the web where it is typically easy to switch images around.
几年前我也遇到过同样的问题,我们的界面团队向我们推荐了 SIFr。 http://wiki.novemberborn.net/sifr/
您将字体嵌入到 Flash 影片中,然后然后使用 SIFr JavaScript 将文本动态转换为字体。 因为它是客户端,所以不会对服务器端产生影响。
如果用户没有安装 Flash 或 JavaScript,他们将获得最接近的网络友好字体。
作为一个额外的好处:因为你的内容仍然是文本——谷歌可以搜索和索引内容——一个巨大的搜索引擎优化优化。
I had the same problem a few years back and our interface team pointed us to SIFr. http://wiki.novemberborn.net/sifr/
You embed your font into a Flash movie and then use the SIFr JavaScript to dynamically convert your text into your font. Because it's client-side, there is no server-side impact.
If the user doesn't have Flash or JavaScript installed, they get the closest web-friendly font.
As an added bonus: because your content is still Text -- Google can search and index the content -- a huge SEO optimization.
由于缓存的原因,我宁愿只将图像 url 添加到 resx 中。 静态内容(即纯文件)的缓存比生成的内容要好得多。
Because of caching, I'd rather add only the image url into the resx. Caching is much better for static content (i-e plain files ) than for generated content.
对于将文本放入图像中,我会非常谨慎,具有适当字体系列后备的 CSS 可能是基于可访问性和良好的 MVC 基础的正确响应。
在真正需要生成的地方,我认为 Kiblee 和 JayArr 概述了很好的解决方案
I'd be very cautious about putting text in images at all, CSS with appropriate font-family fallback is probably the correct response on accessibility and good MVC grounds.
Where generation really is required I think Kiblee and JayArr outline good solutions