简体   繁体   English

调整大小,使用javascript从中心裁剪图像

[英]resize, crop from center an image with javascript

Wonder if anyone can help, I'm looking for a way to take an image path which will be varying sizes - and then create a fixed height and width thumbnail (136x75) from that, cropping from the center point. 不知道是否有人可以提供帮助,我正在寻找一种方法来拍摄尺寸不同的图像路径 - 然后创建一个固定的高度和宽度缩略图(136x75),从中心点裁剪。

I can't really do this in PHP as I need to do this on the fly in the js because Im reading a xml file which contains the image paths, and loading them in via javascript. 我不能在PHP中真正做到这一点,因为我需要在js中动态执行此操作,因为我正在读取包含图像路径的xml文件,并通过javascript加载它们。

I'm just trying to find a script or build one, which will figure out weather to size to the width or height (depending on landscape or portrait ratio of orginal image?) and then crop from the center to the final 136x75 我只是试图找到一个脚本或构建一个脚本,它将根据宽度或高度(取决于原始图像的纵向或纵向比例?)来确定天气尺寸,然后从中心到最终的136x75进行裁剪

Anyone got any good suggestions on how to do this, or an existing solution ? 任何人都有关于如何做到这一点或现有解决方案的任何好建议?

Thanks for looking, 谢谢你的期待,

use the css clip style 使用css剪辑样式

CSS Clip CSS剪辑

EDIT: The wrapper part of the code it shows should prevent absolute positioning malfunctions 编辑:它显示的代码的包装部分应该防止绝对定位故障

<div class="clipwrapper"> <--- this gets set to position:relative so it shouldnt break the image out of the carosel
    <div class="clip"> <--- this gets the absolute position 
     <img src="castle.jpg" />
    </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM