1

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);
j08691
  • 204,283
  • 31
  • 260
  • 272
ivva
  • 2,819
  • 9
  • 31
  • 64

1 Answers1

2

Unless you really want to do this in php, you can just use css and set the max-widthand max-height properties of your image to the maximum size, and the widthand 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"/>
Community
  • 1
  • 1
Juan Cortés
  • 20,634
  • 8
  • 68
  • 91
  • In my controller when I create thumb I have: ```if ($width > $max_width) { $height = ($max_width / $width) * $height; $width = $max_width; }``` and I tried your code and it's fine but using this in my controller heght becomes smaller than 179px. My div is with height: 179px and there is white space. But I'm using this code in controller to preserve dimensions. Should I change height? – ivva Dec 10 '15 at 14:34