通过设置自定义 CSS 宽度来调整视图中图像的大小/缩放

发布于 2024-11-06 13:28:05 字数 903 浏览 0 评论 0原文

问题

我正在 Drupal 站点上进行一些维护和更改,但我不是专家。我的问题如下。我有一个视图,它通过获取一些字段值并将它们放入表列中来生成 HTML 表。其中一个字段是图像。不幸的是,每个图像都有不同的大小(图像是由用户上传的),因此整个表格看起来很难看。我想调整图像大小/缩放图像,使它们都具有相同的宽度。我知道我可以使用 CSS 将图像宽度设置为固定值,并相应调整高度:

<img src="..." style="width:70px"/>

不幸的是,我不知道在处理视图时如何使 Drupal 输出此自定义 HTML。目前生成的 HTML 看起来像这样:

<img 
  class="imagefield imagefield-field_imgsmall" 
  width="100" 
  height="39" 
  alt="" 
  src="http://www.mysite.org/sites/default/files/foobar.png?1292948397">

我猜这是由视图的字段之一(即 field_imgsmall)生成的。

第一个问题是:src URL 中 ? 后面的数字是什么?它从哪里来? (每个图像在相应的 src URL 中都有不同的编号)

我尝试过的

我注意到,在“编辑视图”模式下,选择字段时,我可以选中选项重写该字段的输出,然后我可以混合 HTML 和替换模式。但是,我发现我可以使用的替换模式之一 ([field_imgsmall_fid]) 实际上生成了上面的整个 HTML...所以我无法自定义它。

我能做些什么?我是否走错了方向?

Problem

I'm doing some maintenance and changes on a Drupal site, but I'm not an expert. My problem is the following. I have a view that produces an HTML table by fetching some field values and putting them into the table columns. One of these field is an image. Unfortunately each image has a different size (images are uploaded by users), and so the overall table looks ugly. I would like to resize/scale images so that they all have the same width. I know I can use CSS to set the image width to a fixed value, and let the height adjust accordingly:

<img src="..." style="width:70px"/>

Unfortunately I don't know how to make Drupal output this custom HTML when processing my view. Currently the produced HTML looks like this:

<img 
  class="imagefield imagefield-field_imgsmall" 
  width="100" 
  height="39" 
  alt="" 
  src="http://www.mysite.org/sites/default/files/foobar.png?1292948397">

and I guess this is produced by one of the view's fields (namely field_imgsmall).

First question is: what is that number after the ? in the src URL? And where does it come from? (Each image has a different number in the corresponding src URL)

What I've tried

I've noticed that in the "edit view" mode, when selecting a field, I can check the option Rewrite the output of this field, and there I can mix HTML and substitution patterns. However, I've seen that one of the substitution patterns that's available to me ([field_imgsmall_fid]) is actually producing the entire HTML above ... so I can't customize it.

What can I do? Am I going in a totally wrong direction?

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

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

发布评论

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

评论(1

秋叶绚丽 2024-11-13 13:28:05

您应该查看 imagecache 模块,它允许您调整图像大小(并缓存结果,因此调整大小过程很少发生)。

这是一个演练:

http://2bits.com /articles/drupal-using-imagecache-with-views-and-cck-imagefields.html

You should look into the imagecache module, which allows you to resize images (and cache the results, so the resizing process rarely happens).

Here's a walkthrough:

http://2bits.com/articles/drupal-using-imagecache-with-views-and-cck-imagefields.html

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