Jump to content
php.lv forumi

img size


MārisL

Recommended Posts

  • 3 weeks later...

labākais veids "aspect ratio"

kas ir aspect ratio

 

<?
function ResizeImage($imageNamePath, $target) {
$mysock = getimagesize("$imageNamePath");

$width = $mysock[0];
$height = $mysock[1];

If ($width > $target OR $height > $target)
{

if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}

$width = round($width * $percentage);
$height = round($height * $percentage);
}

$imageSize['width'] = $width;
$imageSize['height'] = $height;

return $imageSize;

}
?>

 

un ar sekojošo kodu resaizo bildi

 

$sizeAry = ResizeImage("$pathtopicture", 500);
echo "<img src='" . $pathtopicture . "' width='" . $sizeAry['width'] . "' height='" . $sizeAry['height'] . "'>";

500 pasaka funkcijai cik ir maksimalie izmeri pirms tiek samazinata bilde. Ceru ka šāds noderēs..

 

 

- ja nepalīdz tad

list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");

 

jeb <img src='' ... width='45'> :)

Link to comment
Share on other sites

×
×
  • Create New...