通过JS,按照原比例控制图片尺寸
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Js压缩图片</title>
<script type="text/javascript" >
//img:图片对象
// w:宽度
// h:高度
function ctlImg(img, w, h) {
var img_Width = w;
var img_Height = h;
var w = img.width;
var h = img.height;
if (img.width > img_Width && img.height > img_Height) {
if (w / img_Width > h / img_Height) {
img.width = img_Width;
img.height = parseInt(img_Width / w * h);
}
else {
img.height = img_Height;
img.width = parseInt(img_Height / h * w);
}
return true;
}
if (w > img_Width) {
img.width = img_Width;
img.height = parseInt(img_Width * (h / w));
} else if (h > img_Height) {
img.height = img_Height;
img.width = parseInt(img_Height * (w / h));
}
return true;
}
</script>
</head>
<body >
<img alt="" src="1.jpg " onload="ctlImg(this,80,60)"/>
<img alt="" src="2.jpg " onload="ctlImg(this,800000,600)"/>
<img alt="" src="3.jpg " onload="ctlImg(this,80,60)"/>
<img alt="" src="4.jpg " onload="ctlImg(this,8000,100)"/>
</body>
</html>
通过JS,按照原比例控制图片尺寸的更多相关文章
- js 压缩图片(只缩小体积,不更改图片尺寸)
1.情景展示 如上图所示,点击上传图片按钮,调用手机摄像头拍照功能. <input onchange="javascript:imgFun.uploadPicture();&quo ...
- vue中 js获取图片尺寸 设置不同样式
1.JS: 请求到后端数据后 判断图片尺寸 2.HTML代码 根据设置的类型,给图片添加不同的样式 3.CSS代码 添加不同尺寸的样式
- 大屏iPhone的适配 +iOS 图片尺寸要求
摘自:http://blog.ibireme.com/2014/09/16/adapted_to_iphone6/ 苹果公司官网设计介绍到:Retina显示屏的超高像素密度已超过人眼能分辨的范围.Re ...
- angular-file-upload封装为指令+图片尺寸限制
不了解angular-file-upload基础使用 请先参考http://blog.csdn.net/lai_xu/article/details/49535847 博客地址 下文如果有更好的建议请 ...
- ajaxfileupload批量上传文件+图片尺寸限制
1.首先展示ajaxfileupload代码,在这里修改为批量上传 //ajaxfileupload不展示全部代码,这是修改前与修改后代码对比,目的是上传多个文件 createUploadForm: ...
- C#根据屏幕分辨率改变图片尺寸
最近工作中遇到一个问题,就是需要将程序文件夹中的图片根据此时电脑屏幕的分辨率来重新改变图片尺寸 以下为代码实现过程: 1.获取文件夹中的图片,此文件夹名为exe程序同目录下 //读取文件夹中文件 Di ...
- 【js】【图片瀑布流】js瀑布流显示图片20180315
js实现把图片用瀑布流显示,只需要“jquery-1.11.2.min.js”. js: //瀑布流显示图片 var WaterfallImg = { option: { maxWidth: 850, ...
- php canvas 前端JS压缩,获取图片二进制流数据并上传
<?php if(isset($_GET['upload']) && $_GET['upload'] == 'img'){ //二进制数据流 $data = file_get_c ...
- Python读取图片尺寸、图片格式
Python读取图片尺寸.图片格式 需要用到PIL模块,使用pip安装Pillow.Pillow是从PIL fork过来的Python 图片库. from PIL import Image im = ...
随机推荐
- win10右击windows键没有反应解决方案(1707版本)
按Win+R打开运行,输入“regedit”打开注册表编辑器. 2.在“HKEY_CLASSES_ROOT”主键下找到“linkfile”或者".lnkfile"字符串值项,在右侧 ...
- 杭电ACM刷题(2):1005,Number Sequence 标签: 杭电acmC语言 2017-05-11 22:43 116人阅读
Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...
- 适合新手的Python爬虫小程序
介绍:此程序是使用python做的一个爬虫小程序 爬取了python百度百科中的部分内容,因为这个demo是根据网站中的静态结构爬取的,所以如果百度百科词条的html结构发生变化 需要修改部分内容. ...
- SDUT 3376 数据结构实验之查找四:二分查找
数据结构实验之查找四:二分查找 Time Limit: 20MS Memory Limit: 65536KB Submit Statistic Problem Description 在一个给定的无重 ...
- img中 src 中文路径解决办法
最近有个项目场景如下:需要后台遍历图片.视频所在的文件夹,获取的到的路径传递到JSP页面,使用<img src="具体的路径">显示图片.遇到的问题:如果图片的路径.图 ...
- spring、spring mvc以及IOC的阅读
spring vs spring-mvc spring是应用级框架 spring mvc只是一个mvc框架 spring现在包含很多子模块,我们用的最多的是依赖注入. spring模块可分为以下: C ...
- Required plugin could not be found. Videos requires to install plugins to play files of the following types : MPEG-4-AAC decoder and H.264 decoder
https://linuxconfig.org/how-to-install-mpeg-4-aac-decoder-for-centos-7-linux 记得联网情况下才能下载.
- java.io.FileNotFoundException: res/drawable/title_bar_shadow.9.png
ERROR/AndroidRuntime(803): Caused by: java.io.FileNotFoundException: res/drawable/title_bar_shadow.9 ...
- Unity中Awake的执行时间点
https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html 根据官方文档,Awake的实际执行点,应该是对应mono脚本所在物体 ...
- C#校验算法列举
以下是工作中常用的几种校验算法,后期将不断更新 和校验 /// <summary> /// CS和校验 /// </summary> /// <param name=&q ...