I would like to resize an image proportionally to 500px X 500px I found the below code from the net however the article didn't have an example of how to use the script, can someone just get me started on how to display the resized image?
$filename = 'test.png';
list($width, $height, $type, $attr) = getimagesize($filename);
$orig_w = $width;
$orig_h = $height;
$MIN_W = 500;
$MIN_H = 500;
$MAX_H = 500;
$MAX_W = 500;
function image_resize_up($orig_w, $orig_h, $MIN_W, $MIN_H){
$ratio = $orig_w * 1.0 / $orig_h;
$w_undersized = ($orig_w < $MIN_W);
$h_undersized = ($orig_h < $MIN_H);
if ($w_undersized OR $h_undersized)
{
$new_w = round( max($MIN_W, $ratio * $MIN_H) );
$new_h = round( max($MIN_H, $MIN_W / $ratio) );
return array('width' => $new_w, 'height' => $new_h);
}
return null;
}
function image_resize_down($orig_w, $orig_h, $MAX_W, $MAX_H){
$ratio = $orig_w * 1.0 / $orig_h;
$w_undersized = ($orig_w > $MAX_W);
$h_undersized = ($orig_h > $MAX_H);
if ($w_undersized OR $h_undersized)
{
$new_w = round( min($MAX_W, $ratio * $MAX_H) );
$new_h = round( min($MAX_H, $MAX_W / $ratio) );
return array('width' => $new_w, 'height' => $new_h);
}
return null;
}
echo $w_undersized;
I tried
echo "<img src=".$filename.$new_w.$new_h.">";//gives me undefined variable and the image isn't resized.