通过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 = ...
随机推荐
- spirng boot web配置开发
spring-booter-starter-web是spring-boot web发开的核心,自动配置信息存储在spring-boot-autoconfigure.jar 下面的web目录里面,包含了 ...
- linux ftp、sftp、telnet服务开通、更改Orale最大连接数
1 ftp服务开通 1.1 检测vsftpd是否安装及启动 先用service vsftpd status 来查看ftp是否开启.也可以使用ps -ef | grep ftp 来查看本地是否含有包含f ...
- 基于jQuery的Tooltip
近来,要开发一个关务管理系统,为了增加系统美观度,自己开发了一个基于jQuery框的的小插件,与大家分享一下,希望大家能给我提出宝贵修改意见. 下面开发说明使用方法和内容: 一.引用jQuery框架, ...
- sina 接口 根据ip获取各个国家和地区
http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=ip
- 【android】setOnItemClickListener cannot be used with a spinner的错误
错误提示: java.lang.RuntimeException: Unable to start activity ComponentInfo{xx activity}: java.lang.Run ...
- angular 分页
http://jsfiddle.net/SAWsA/11/# <html xmlns:ng="http://angularjs.org" ng-app lang=" ...
- 关于文本PDG的字体
作者:马健邮箱:stronghorse_mj@hotmail.com发布:2008.08.03 有不少人在问为什么有些文本PDG在SSREADER里看到的是宋体,在Acobat里看到的是黑体,其实原因 ...
- vs code 提示快捷键
1.ctrl+space 基本上被输入法快捷键占用 文件->首选项->键盘快捷方式(ctrl+k,ctrl+s):搜索 editor.action.triggerSuggest 换成 ct ...
- [转]Passing Managed Structures With Strings To Unmanaged Code Part 3
1. Introduction. 1.1 In part 1 of this series of blogs we studied how to pass a managed structure (w ...
- WeChat 微信公众号开发步骤
WeChat 微信公众号开发步骤 一.什么是微信公众号? 微信公众号是开发者或商家在微信公众平台上申请的应用账号,该帐号与QQ账号互通,通过公众号,商家可在微信平台上实现和特定群体的文字.图片.语音 ...