note 92248 modified in function.getimagesize by danbrown
| From: | danbrown@php.net | Date: | Thu, 16 Jul 2009 18:55:48 +0000 |
| Subject: | note 92248 modified in function.getimagesize by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-158378@lists.php.net to get a copy of this message | ||
Well there are a lot of image scaling functions here. Here is my take on it.
<?php
function get_scaled_dim_array($img,$max_w = 100, $max_h = NULL){
if(is_null($max_h)){
$max_h = $max_w;
}
if (file_exists($img)){
list($img_w,$img_h) = getimagesize($img);
$f = min($max_w/$img_w, $max_h/$img_h, 1);
$w = round($f * $img_w);
$h = round($f * $img_h);
return array($w,$h);
}
return NULL;
}
?>
--was--
Well there are a lot of image scaling functions here. Here is my take on it.
<?
function get_scaled_dim_array($img,$max_w = 100, $max_h = NULL){
if(is_null($max_h)){
$max_h = $max_w;
}
if (file_exists($img)){
list($img_w,$img_h) = getimagesize($img);
$f = min($max_w/$img_w, $max_h/$img_h, 1);
$w = round($f * $img_w);
$h = round($f * $img_h);
return array($w,$h);
}
return NULL;
}
?>
http://php.net/manual/en/function.getimagesize.php