Reputation: 2949
I'm trying to make thumb and preserve its original proportions. Thumb's div should have width:189px and height 179px. But now, the thumb itself has bigger height and proportions are different. How to do that?
I'm trying with this:
<div class="thumbnail image-thumbnail">
<a href="someurl"><img src="thumb_src" class="thumb"/></a>
</div>
.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%;
}
$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);
Upvotes: 1
Views: 127
Reputation: 21082
Unless you really want to do this in php, you can just use css and set the max-width
and max-height
properties of your image to the maximum size, and the width
and height
to auto
to preserve the aspect ratio:
img{
max-width:189px;
max-height:179px;
width: auto;
height: auto;
}
img{
max-width:180px;
max-height:179px;
width: auto;
height: auto;
}
<img src="http://i.imgur.com/pszAeGh.png"/>
Upvotes: 2