javascript实现获取图片大小及图片等比缩放的方法
作者:Blue Sky ...... 时间:2024-04-16 10:29:33
本文实例讲述了javascript实现获取图片大小及图片等比缩放的方法。分享给大家供大家参考,具体如下:
获取图片大小:
var originImage = new Image();
function GetImageWidth(oImage) {
if (originImage.src != oImage.src) originImage.src = oImage.src;
return originImage.width;
}
function GetImageHeight(oImage) {
if (originImage.src != oImage.src) originImage.src = oImage.src;
return originImage.height;
}
图片等比缩放:
function SetImage(ImgD, FitWidth, FitHeight) {
var image = new Image();
image.src = ImgD.src;
if (image.width > 0 && image.height > 0) {
if (image.width / image.height >= FitWidth / FitHeight) {
if (image.width > FitWidth) {
ImgD.width = FitWidth;
ImgD.height = (image.height * FitWidth) / image.width;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
} else {
if (image.height > FitHeight) {
ImgD.height = FitHeight;
ImgD.width = (image.width * FitHeight) / image.height;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
}
}
}
希望本文所述对大家JavaScript程序设计有所帮助。
标签:javascript,图片大小,图片缩放
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
vue表单自定义校验规则介绍
2024-04-30 10:25:10
pytorch 一行代码查看网络参数总量的实现
2023-04-23 17:42:36
![](https://img.aspxhome.com/file/2023/8/89138_0s.jpg)
Python requests库用法实例详解
2021-03-31 19:36:30
Python中BeautifuSoup库的用法使用详解
2023-11-19 04:52:48
python 指定源路径来解决import问题的操作
2023-04-28 00:03:01
![](https://img.aspxhome.com/file/2023/2/131112_0s.jpg)
Python readline()和readlines()函数实现按行读取文件
2022-02-21 13:19:36
Python2.x中文乱码问题解决方法
2023-09-20 14:35:35
![](https://img.aspxhome.com/file/2023/4/105084_0s.png)
python PIL和CV对 图片的读取,显示,裁剪,保存实现方法
2022-02-06 09:35:07
mysql索引失效的五种情况分析
2024-01-24 16:27:22
![](https://img.aspxhome.com/file/2023/4/121574_0s.png)
用ASP和SQL语句动态的创建Access表
2008-10-14 16:59:00
如何实现一个简易版的vuex持久化工具
2024-04-30 10:34:29
浅谈django2.0 ForeignKey参数的变化
2022-03-26 10:11:30
Windows下Python使用Pandas模块操作Excel文件的教程
2021-01-05 23:07:40
![](https://img.aspxhome.com/file/2023/1/69021_0s.jpg)
Python使用tkinter库实现文本显示用户输入功能示例
2023-09-21 11:00:17
![](https://img.aspxhome.com/file/2023/1/105271_0s.gif)
Mysql数据库备份和还原常用的命令
2011-12-01 10:41:54
Python中xml和dict格式转换的示例代码
2021-07-18 21:30:10
python数据类型bytes 和 bytearray的使用与区别
2021-08-26 05:51:48
JavaScript中遍历对象的property的3种方法介绍
2024-06-05 09:31:19
![](https://img.aspxhome.com/file/2023/8/122788_0s.png)
在数据库中自动生成编号的实现方法分享
2011-11-03 16:55:24
2008圣诞节网站特色Logo不完全点评
2008-12-25 18:35:00
![](https://img.aspxhome.com/file/UploadPic/up/1-shengdanjie.jpg)