我有以下两个链接
原始图片:
已调整大小图片:
我和Wappalyzer一起检查过,但没有发现任何技术。
我想做类似这样的事情。是否有任何插件?
PS:我知道市场上有很多插件,但我希望它与此类似。
这也是该网站的原始链接:
http://static01.nyt.com/images/2014/11/16/realestate/16BOERUMSUB/16BOERUMSUB-master495.jpg
他们添加了一些处理程序。
答案 0 :(得分:0)
此功能将调整具有指定尺寸组的任何图像的大小,同时保留纵横比。务必在每个图像加载后调用该功能。
function resize_images(maxht, maxwt, minht, minwt) {
var imgs = document.getElementsByTagName('img');
var resize_image = function(img, newht, newwt) {
img.height = newht;
img.width = newwt;
};
for (var i = 0; i < imgs.length; i++) {
var img = imgs[i];
if (img.height > maxht || img.width > maxwt) {
// Use Ratios to constraint proportions.
var old_ratio = img.height / img.width;
var min_ratio = minht / minwt;
// If it can scale perfectly.
if (old_ratio === min_ratio) {
resize_image(img, minht, minwt);
}
else {
var newdim = [img.height, img.width];
newdim[0] = minht; // Sort out the height first
// ratio = ht / wt => wt = ht / ratio.
newdim[1] = newdim[0] / old_ratio;
// Do we still have to sort out the width?
if (newdim[1] > maxwt) {
newdim[1] = minwt;
newdim[0] = newdim[1] * old_ratio;
}
resize_image(img, newdim[0], newdim[1]);
}
}
}
}