简体   繁体   English

如何将网页上每张图片的大小加倍?

[英]How can I double the size of every image on a web page?

There's a web page that I would like to double the size of all images on. 有一个网页,我想将所有图像的大小加倍。 I don't know any JavaScript or CSS. 我不知道任何JavaScript或CSS。 Can someone write me some code please? 有人可以给我写一些代码吗? I tried this: 我试过这个:

Array.prototype.forEach.call(document.getElementsByTagName('img'),function(i){
    i.width = i.width * 2;i.height = i.height * 2
});

But I don't know what I'm doing, and it's not working. 但我不知道我在做什么,而且它不起作用。 Please help. 请帮忙。

This is what the elements that I'm trying to double look like, if it's any help at all: 这就是我试图加倍的元素,如果有任何帮助的话:

Reference: http://boards.4chan.org/g/ 参考: http //boards.4chan.org/g/

I've discovered an excellent feature that this website has for it's users, including built in customized viewing of their Thumbnail Images! 我发现这个网站为用户提供了一个很棒的功能,包括内置的缩略图图像的自定义查看功能!

The 4Chan Homepage Settings Menu 4Chan主页设置菜单

That menu provides a whole lot of options to configure the webpage on how you see fit. 该菜单提供了很多选项来配置您认为合适的网页。 I was astounded to see a Custom CSS feature that shows a CSS Box which will accept your own custom markup to tailor the site down to markup level! 我很惊讶地发现Custom CSS功能显示了一个CSS Box ,它将接受您自己的自定义标记,以便将网站定制到标记级别! More on that in a bit. 更多关于这一点。

First, I want to mention that they do provide TWO ready to use options that should satisfy your Thumbnail viewing requirements. 首先,我想提一下它们确实提供了两个可以满足缩略图查看要求的即用型选项。

Bounty EDIT: Users of the 4chan-x Greasemonkey script already have these 2 options in 4chan Qt ≪Quality thumbnails≫ Settings menu. 赏金编辑: 4chan-x Greasemonkey脚本的用户已经在4chan Qt«质量缩略图设置菜单中有这两个选项。 Skip to the next EDIT below if your using this script. 如果您使用此脚本,请跳至下面的下一个编辑。

Take a look at this screenshot that show 3 steps to perform, with step 2 being one or the other. 看一下这个屏幕截图,其中显示了要执行的3个步骤,其中第2步是其中之一。

Right-click the image below and view in full size if that helps: 右键单击下面的图像,如果有帮助,请以完整大小查看

Open Image in New Tab / View Image

在此输入图像描述

In Step 1 above, notice that the Settings reflect the 4chan Homepage and not the script. 在上面的步骤1中 ,请注意Settings反映4chan Homepage而不是脚本。

In Step 2a above, this will closely reproduce the double image size for average images, but if those images are super large, they will use the available browsers width. 在上面的步骤2a中 ,这将为平均图像紧密地再现双图像尺寸,但是如果这些图像是超大的,则它们将使用可用的浏览器宽度。

In Step 2b above, this choice instead will show a super large image if it exists up to the browsers width size. 在上面的步骤2b中 ,如果存在直到浏览器宽度大小,则该选择将显示超大图像。

If neither of these two ready-to-use thumbnail options suits your taste, keep reading. 如果这两个即用型缩略图选项都不适合您的口味,请继续阅读。

Since your original goal is to see the thumbnails at twice the size, or 200% , I analyzed the webpage to determine the most minimal settings required to show these Thumbnail Images at that size, but note many will be blurry at twice the size since the quality isn't increased. 由于您最初的目标是以两倍大小或200%查看缩略图,因此我分析了网页以确定以该大小显示这些缩略图图像所需的最小设置,但请注意,由于质量没有提高。 See Bounty EDIT below for solution for images that are not blurry at ANY size. 有关任何尺寸均不模糊的图像的解决方案,请参阅下面的Bounty EDIT。

Having said that, you can choose 150% to minimize the blur while still enlarging it, or choose the value that is acceptable to you if you did not want to use Greasemonkey. 话虽如此,您可以选择150%来最小化模糊,同时仍然放大模糊,或者如果您不想使用Greasemonkey,请选择您可接受的值。


Bounty EDIT: 赏金编辑:

The blurry images are no longer an issue when using these CSS Settings with 4chan-x Greasemonkey Script to have thumbnails twice the size . 使用带有4chan-x Greasemonkey脚本的 CSS设置时,模糊图像不再是一个问题, 缩略图的大小是其两倍

Note you will need to remove a default checkmark that is automatically applied for Disable 4chan's extension in the Greasemonkey Script, accessible by clicking the 4chan Qt ≪Quality thumbnails≫ Settings link at the top-right corner of the webpage. 请注意,您需要删除在Greasemonkey脚本中自动应用于Disable 4chan's extension的默认选中标记,可通过单击网页右上角的4chan Qt«质量缩略图设置链接访问该标记

Once you exit that settings menu, enter the 4chan Homepage Settings Menu . 退出设置菜单后,进入4chan 主页设置菜单 Remove all checkmarks, except for Custom CSS. 删除自定义CSS 之外的 所有复选标记。 To be sure, the image above did not remove all the checkmarks for which 4chan-x recommends. 可以肯定的是,上面的图像没有删除4chan-x推荐的所有复选标记。


Caution: Using the Custom CSS Settings option can make the Settings Menu inaccessible! 警告:使用“ 自定义CSS设置”选项可能会使“设置”菜单无法访问! You'll need to use the browsers built in inspect element to make live changes on-the-fly to regain control. 您需要使用inspect element内置的浏览器即时进行实时更改以重新获得控制权。

The box below is not an image. 下面的框不是图像。 Select, copy, and then paste this CSS into the Settings Menu CSS Box: 选择,复制,然后将此CSS粘贴到设置菜单CSS框中:

div.file, a.fileThumb img {
  width: 200% !important;
  height: 200% !important;
  float: left; 
}

.fileInfo {
  margin: 10px;
}

To be clear, here's a screenshot of that box: 要清楚,这是该框的屏幕截图:
在此输入图像描述

After you paste the above code into the CSS Box , press the Save CSS Button and ensure you have a Checkmark for Custom CSS and then press the SAVE Button to exit. 将上面的代码粘贴到CSS Box ,按“ Save CSS Button ,确保您有Custom CSS的复选Checkmark ,然后按“ SAVE Button退出。

The page will then refresh itself with these new settings. 然后,该页面将使用这些新设置刷新自身。 Enjoy your 2x Thumbnails. 享受你的2x缩略图。

Bounty EDIT: Reminder that above image shows checkmarks in Essential section that should be removed. Bounty编辑:提醒上面的图片显示了Essential部分中应该删除的复选标记。 To be sure, the homepage top-right will have 4Chan's Original Settings Menu in middle: 可以肯定的是,右上方的主页将在中间设置4Chan的原始设置菜单:

[4chan Qt ≪Quality thumbnails≫ Settings] [Settings] [Home] [4chan Qt«质量缩略图设置] [设置] [主页]

As I mentioned in a comment previously, your code won't touch the images which are background images to non <img> html elements because of CSS property background-image . 正如我之前在评论中提到的,由于CSS属性background-image ,您的代码不会将背景图像的图像触摸到非<img> html元素。

So you need to run both your code to double <img> tags. 所以你需要运行你的代码来加倍<img>标签。

Also you need to set CSS property background-size to 200% Auto . 您还需要将CSS属性background-size200% Auto

Now ofcourse the question, is to what you want to add the css property. 现在问题是,你想要添加css属性。 Chances are that all those images on 4chan are also links. 有可能4chan上的所有图像也都是链接。 So they must be anchor <a> tags with background-image . 所以他们必须使用background-image锚定<a>标签。

Sorry I am in office, so I won't open up 4chan to confirm that. 对不起,我在办公室,所以我不打开4chan确认。

But you can try this code in this same website: 但是你可以在同一个网站上试试这个代码:

$('a').css('background-size', '200% Auto');

My quick solution uses jQuery, but you get the idea. 我的快速解决方案使用jQuery,但你明白了。

Update: 更新:

Array.prototype.forEach.call(document.getElementsByTagName('img'),function(i){i.width = i.width * 2;i.height = i.height * 2});

Array.prototype.forEach.call(document.getElementsByTagName('a'),function(i){i.style['background-size'] = '200% Auto'; });

I assume that even a CSS solution would work for you (from your question). 我假设即使是CSS解决方案也适合你(来自你的问题)。 If there is no restriction on having real DOM width and height, you can also go for CSS transforms. 如果对实际DOM宽度和高度没有限制,您也可以进行CSS转换。

img {
    -webkit-transform: scale(2,2);
    -moz-transform: scale(2,2);
    -ms-transform: scale(2,2);
    /* etc. */
    transform: scale(2,2);
}

In JavaScript try: 在JavaScript中尝试:

for (i=0; i < document.images.length; i++) {
    document.images[i].height *= 2;
    document.images[i].width *= 2; 
}

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

相关问题 如何将网页上的图像大小加倍? - How do I double the size of an image on a web page? 如何在网页中打印图像,以适合纸张尺寸(A3,A4,A5等)? - How can I print an image in a web page, fitting the paper size (A3, A4, A5, etc)? 如何在页面上的每个图像周围添加链接? - How can I add a link around every image on a page? 如何通过双击将一个单词作为网页输入? - How can I take a word as a input from a web page by double clicking on it? 如何在点击时将图像尺寸加倍 - How to double Image Size on Click 如何在我的Web应用程序中使用单个模式,并避免每个页面上出现重复的html? - How can I use a single modal across my web application and avoid repetative html on every page? 如何使用 static 变量制作 js function? 我如何为页面中的每个图像运行这些功能? - How to make js function with static variables ? How can i run these functions for every image in the page? 如何使用Javascript获取网页上图像的文件大小? - How do you get the file size of an image on the web page with Javascript? 如何每分钟更新一次此网页? - How do I update this web page every minute? 如何在此脚本中更改图像的大小? - How can I change the size of the image in this script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM