algoritma resize image

waa,, beberapa hari ini cari2 algoritma resize imge nggak ketemu2,, waa,, pussingg dah,,

padahal ketentuan nya cuman 2 :

1. width x heigth nggak boleh lebih dari 500×300

2. resize nya harus proporsional

alogoritmanya piye yo,, pusing pusing pusing,, huft.. :( (

One comment

  1. coolza says:

    finally,, i find the way

    $max_width = 500;
    $max_height = 300;
    if($width>=$max_width)
    { $scale = (float)$max_width/(float)$width;
    $newwidth = (int) $width*$scale;
    $newheight = (int) $height*$scale;
    }
    if($newheight>$max_height)
    { $scale = (float)$max_height/(float)$newheight;
    $newwidth = (int) $newwidth*$scale;
    $newheight = (int) $newheight*$scale;
    }
    if ($width< $max_width)
    {
    $newwidth=$width;
    }
    if ($height<$max_height)
    {
    $newheight=$height;
    }

Leave a Reply

*


+ 2 = three