我试图做拇指并保持其原始比例。拇指的div应该有宽度:189px和高度179px。但现在,拇指本身的高度更大,比例也不同。怎么做?
我正在尝试这个:
<div class="thumbnail image-thumbnail">
<a href="someurl"><img src="thumb_src" class="thumb"/></a>
</div>
&#13;
.thumbnail {
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
display: block;
line-height: 1.42857;
margin-bottom: 20px;
padding: 4px;
transition: all 0.2s ease-in-out 0s;
}
.image-thumbnail {
border: 0 none;
float: left;
margin-right: 1%;
margin-top: 10px;
padding: 0 !important;
width: 19.2%;
}
.thumb {
display: block !important;
max-height: 178px;
min-height: 178px;
min-width: 100%;
}
&#13;
$max_width = 289;
$path = $_REQUEST['path'];
list($orig_width, $orig_height) = getimagesize($path);
$width = $orig_width;
$height = $orig_height;
# wider
if ($width > $max_width) {
$height = ($max_width / $width) * $height;
$width = $max_width;
}
$image = Image::factory ( $path, 'GD' );
$image->resize($width,$height)->save($tmbPath,100);
&#13;
答案 0 :(得分:2)
除非你真的想要do this in php,否则你可以使用css并将图片的max-width
和max-height
属性设置为最大尺寸,width
和height
到auto
以保留宽高比:
img{
max-width:189px;
max-height:179px;
width: auto;
height: auto;
}
img{
max-width:180px;
max-height:179px;
width: auto;
height: auto;
}
&#13;
<img src="http://i.imgur.com/pszAeGh.png"/>
&#13;