I have been creating an image uploading site for a while now but have been stuck on a certain part of it. On the second page, once the upload has been completed, i have displayed the various links you would expect. However. I would like to add a thumbnail to the page, or even a bigger picture, but it needs to be a certain width. I have tried many times to write a little script to take the dimensions and apply some maths to it, but to no avail.
I would really like if someone had a script or an idea how to do the above. Remember all the image sizes uploaded are different and i would want a 50×50 image being blown up to 250×250.
<?php
function imgResize($width, $height, $target) {
if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}
$width = round($width * $percentage);
$height = round($height * $percentage);
return "width=\"$width\" height=\"$height\"";
}
?>
Thanks,
Harry
Simple math: