调整图像大小后,如何使用 javascript 在单独的窗口中打开图像?
这是我必须为我重新调整图像大小的代码。我不知道该怎么做是让代码在调整大小后打开图像。
所以我希望它是
- 调整图像大小(它已经在这样做)。
- 调整图像大小后,在单独的窗口中打开它
这是为我调整图像大小的代码。
function resize(which, max) {
var elem = document.getElementById(which);
if (elem == undefined || elem == null) return false;
if (max == undefined) max = 1024;
if (elem.width > elem.height) {
elem.width = max;
elem.height = 768;
}
}
This is the code that I have to re-size the image for me. What I don't know how to do is have the code open the image after it has been re-sized.
So what I wish for it to is is
- Resize the image(It is already doing this).
- Once image is re-sized, open it in a separate window
This is the code that re-sizes the image for me.
function resize(which, max) {
var elem = document.getElementById(which);
if (elem == undefined || elem == null) return false;
if (max == undefined) max = 1024;
if (elem.width > elem.height) {
elem.width = max;
elem.height = 768;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该代码实际上并没有调整图片的大小,它只是改变了它的显示方式。如果图像是下载的或在单独的窗口中打开的,则它将是原始图像的尺寸。我认为没有任何方法可以通过 JavaScript 修改图像。
不过,您可以做的是找到一个可以为您执行此操作的程序,并通过 Ajax 调用来调用它。例如,我认为 Gimp 可以处理这个问题,如果您可以从 PHP 脚本调用它,那么您可以通过 Ajax 调用调用该 PHP 脚本并显示它。这是一个复杂的解决方案,但这是我能想到的最好的解决方案。
That code does not actually resize the picture, it just changes how it is displayed. If the image is downloaded or opened in a separate window, it will be the dimensions of the original image. I don't think there is any way of modifying the image through JavaScript.
What you could do, though, is find a program that can do that for you and call that through an Ajax call. For example, I think the Gimp can handle that, and if you can call that from a PHP script, then you can call that PHP script through an Ajax call and display that. It's kind of a complicated solution but that's the best I can think of.
正如 tjameson 指出的那样,JavaScript 并不会真正调整图像的大小。
如果您想将此图像带到新窗口,可以采用以下方法:
如果您希望调整其显示大小,可以在此图像上应用调整大小功能。
As tjameson pointed out, JavaScript doesn't really resize your image.
If you want to take this image to a new window, here is a way to do it:
You can apply the resize function on this image if you want it displayed resized.
我将所需的代码附加到初始调整大小函数中
I appended the needed code to the initial resize function