从中心即时裁剪图像 - Javascript?
我有一堆图像,它们的宽度和高度各不相同。
有些是正方形,有些是矩形,但我希望它们全部都是我选择的宽度和高度。
我知道我可以在中使用 width="" 和 height=""
那么,我正在寻找的是一个可能的 javascript 解决方案,也许使用 jQuery,它将即时从中心裁剪图像?
这可能吗?
I have a bunch of images, that are various sizes, in terms of width and height.
Some are square, some are rectangle, but I'd like all of them to be width and height of my choice.
I know I can use the width="" and height="" in the
So, what I was looking for, is a possible javascript solution, maybe using jQuery, that will crop the images from center on the fly?
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 CSS 将图像放置在容器内。然后确保该容器上设置了溢出:隐藏。
例如:
You can position the images within a container using CSS. Then ensure overflow: hidden is set on that container.
For example:
类似这样的事情!通过设置其位置的左/上属性,您可以模拟裁剪。上面的示例将从图像的顶部和左侧减去 10px。此示例假设图像为 200 像素 x 200 像素,显然需要编辑图像的值。
您可能需要重新定位容器 div,以便图像看起来保留在同一位置。
Something like that! By setting the left/top properties of it's position you can simulate a crop. The above example will take 10px off the top and left of the image. This example assumes the image is 200px by 200px, obviously edit values for your image.
You may need to reposition the container div so that the image looks like it remains in the same place.