note 97564 deleted from function.getimagesize by cmb
| From: | cmb@php.net | Date: | Sun, 18 Dec 2016 09:40:54 +0000 |
| Subject: | note 97564 deleted from function.getimagesize by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208633@lists.php.net to get a copy of this message | ||
Note Submitter: modnyj at gmail dot com
----
A simple method to resize a image keeping the constraint proportions:
<?php
// Constraints
$max_width = 100;
$max_height = 100;
list($width, $height) = getimagesize($img_path);
$ratioh = $max_height/$height;
$ratiow = $max_width/$width;
$ratio = min($ratioh, $ratiow);
// New dimensions
$width = intval($ratio*$width);
$height = intval($ratio*$height);
?>