Html 调整“a href”标签链接中的图像大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1572410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
resize an image in 'a href' tag link
提问by leora
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.
但是如果我希望 href 链接也显示较小尺寸的图像怎么办。所以可以说原始 image.jpg 是 1500x1200,在链接中我想显示它 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>
采纳答案by Ben James
If I understand correctly, you want to control the size of the image that is the target of the href
, using attributes of the a
tag?
如果我理解正确,您想href
使用a
标签的属性来控制作为 目标的图像的大小吗?
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
.
你不能那样做。您最好的选择(从链接源控制大小)是使用服务器端脚本提供图像,该脚本接受查询字符串中的大小参数。喜欢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 :)
当然,如果您只想将图像更改为特定大小,只需调整实际图像的大小并再次上传:)
回答by treznik
Here is a funny solution:
这是一个有趣的解决方案:
<a href="javascript:document.getElementsByTagName('body')[0].innerHTML='<img src=images/image.jpg width=800 height=600>'"><img src="images/image.jpg" width="300" height="214" border="0"></a>
Though personally I would not recommend it, it works. :)
虽然我个人不推荐它,但它有效。:)
回答by Noam Smadja
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.
链接到只有一个的空 html 页面<img src="URL" width="" height=""/>
并将大小应用于它。
回答by kittu
Check out image-resizer in nodejs.
在 nodejs 中查看图像调整器。
Here's the link: https://github.com/jimmynicol/image-resizer
这是链接:https: //github.com/jimmynicol/image-resizer
Or you can use cloudinary nodejs integration which provides a free tier access for first 7500 image transformations
或者您可以使用 cloudinary nodejs 集成,它为前 7500 个图像转换提供免费层访问