在“a href”中调整图像大小标签链接
查看下面的代码,我可以显示较小尺寸的图像
<a href="images/image.jpg"><img src="images/image.jpg" width="300" height="214" border="0"></a>
,但是如果我希望 href 链接也显示较小尺寸的图像怎么办?假设原始 image.jpg 是 1500x1200,在链接中我想显示它 800x600。
无论如何,有没有做这样的事情:
<a href="images/image.jpg" width="800" height="600"><img src="images/image.jpg" width="300" height="214" border="0"></a>
looking at the code below, i can show an image with a smaller size
<a href="images/image.jpg"><img src="images/image.jpg" width="300" height="214" border="0"></a>
but what if i want the href link to show the image with a smaller size as well. so lets say the original image.jpg is 1500x1200 and in the link i want to show it 800x600.
is there anyway to do something like this:
<a href="images/image.jpg" width="800" height="600"><img src="images/image.jpg" width="300" height="214" border="0"></a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果我理解正确的话,您想使用
a
标记的属性来控制作为href
目标的图像的大小?你不能那样做。您最好的选择(用于从链接源控制大小)是使用服务器端脚本提供图像,该脚本接受查询字符串中的大小参数。就像
image.php?img=image.jpg&w=800&h=600
。但这完全是另一个问题,超出了我在这里详细讨论的范围。
当然,如果您只想将图像更改为特定尺寸,只需调整实际图像的大小并再次上传:)
If I understand correctly, you want to control the size of the image that is the target of the
href
, using attributes of thea
tag?You can't do that. Your best bet (for controlling the size from the source of the link) is to serve your images using a server-side script which accepts size parameters in a querystring. Like
image.php?img=image.jpg&w=800&h=600
.But that's a whole other question and would be out of scope for me to go into detail here.
Of course if you want to just change the image to a particular size, just resize the actual image and upload it again :)
这是一个有趣的解决方案:
虽然我个人不推荐它,但它确实有效。 :)
Here is a funny solution:
Though personally I would not recommend it, it works. :)
因为你打开图像本身,这是不可能的。
您可以做的是,
链接到仅包含
的空 html 页面,然后对其应用尺寸。
since you open the image itself it is impossible.
what you can do is,
link to and empty html page with only an
<img src="URL" width="" height=""/>
and apply the size to it.查看nodejs 中的图像缩放器。
这是链接:https://github.com/jimmynicol/image-resizer
或者您可以使用 cloudinary Nodejs 集成,它为前 7500 个图像转换提供免费层访问
Check out image-resizer in nodejs.
Here's the link: https://github.com/jimmynicol/image-resizer
Or you can use cloudinary nodejs integration which provides a free tier access for first 7500 image transformations