日期:2014-05-17 浏览次数:20707 次
<script type="text/javascript">
function getImgSize(img) {
var result = {};
var w = img.width;
var h = img.height;
if (w > 300) {
if (h <= 200) {
result.width = 300;
result.height = Math.ceil(parseInt(h) * 200 / 300);
}
else {
if (w / h == 1.5) {
result.width = 300;
result.height = 200;
}
else if (w / h > 1.5) {
result.width = 300;
result.height = 0;
}
else {
result.width = 0;
result.height = 200;
}
}
}
else {
if (h <= 200) {
result.width = w;
result.height = h;
}
else {
result.height = 200;
result.width = Math.ceil(parseInt(w) * 200 / h);
}
}
return result;
}
window.onload = function() {
var obj = document.getElementsByTagName('table')[0].getElementsByTagName('img');
for (var i = 0; i < obj.length; i ++) {
var wh = getImgSize(obj[i]);
if (wh.width > 0) obj[i].style.width = wh.width + 'px';
if (wh.height > 0) obj[i].style.width = wh.height + 'px';
}
}
</script>
------解决方案--------------------
只需对 img 单边控制就能保持原来的比例
list($width, $height) = getimagesize($result['lujing']);//可能需对$result['lujing']中的路径做适当调整
...<img src="<?php echo $result['lujing']; ?>" <?php echo $width>$height*1.5 ? 'width="300"' : 'height="200"' ?> />....
使用 js 也是一样
------解决方案--------------------
<?php
$a_size = getimagesize('1.jpg');
print_r($a_size);
?>
利用该函数得到的结果去对控制图片的大小
------解决方案--------------------
你把PHP生成的表格代码发上来啊。