Autor Zpráva
juraj
Profil
Zdravím
ako mám upraviť tento kód,keď chcem,aby sa mi obrázok s pevnou šírkou napr 920px a s pevnou výšku
nedeformoval? Napr ako to majú urobene tu
       <div id="p"> 
            <?
          $album = 'fotky/demo/'; //bez lomitka
       $count = 0;
    if (is_dir($album)) {
       // $dirsm = explode('/', $album);
        $last_dirm = $dirs[count($dirsm) - 1];
        ?>

       <? if ($dhm = opendir($album)) {?>
       
       <?
           while (($file = readdir($dhm)) !== false) {
                if ($file == '.' || $file == '..') {} else {

               ?>
               <?
                    if (is_dir($album.'/'.$file)) {
                    ?>
<?
?>
                <?    } else {
                $count++;     

                ?>
                <?  
 $cesta=$album.$file;

$divsirka=700;/*795*/
$divvyska=610;
$PrevSize=900;

$target_height = 600;//600
$target_width = 920;//1020
list($width, $height, $type, $attr) = getimagesize($cesta);
$v_fact = @$target_height / $height ;
$h_fact = @$target_width /$width;

$im_fact = min($v_fact, $h_fact);
  $new_height = $height * $im_fact;
  //echo $_SERVER['HTTP_HOST'];echo $_SERVER['REQUEST_URI'];
 $new_width = $width * $im_fact;

$g= $divvyska-$new_height;
 $top1=$g/2;//umiestnenie do stredu diva ak je malá výska obrayka
 
?>
<div style="max-width:920px;height:600px;border:1px solid green">

<?php if ($divvzska <$new_height){?>

     <center>
     <div id='shadow'>
     <center>
     <img src="<?echo ($cesta); ?>"    width="<? echo $new_width;?>"
    height="<?php   echo $new_height;?>" style="position:relative;top:<?php echo $top1;?>px;margin-top:3px">
     </center>
   </div>
     </center>
<?}else{?>
    <center>
     <img src="<?echo ($cesta); ?>"    width="<? echo $new_width;?>" height="<?php echo $new_height;?>" >
     </center>
      <?}?>
</div>
  <?    } ?>
 <?     }  }?>
         <?
     closedir($dhm);
        }
    }
?>
</div>
Jcas
Profil
No nevím. Jestli máš nějaký prostor, který má pevnou šířku i výšku
a celý tento prostor chceš vyplnit obrázkem,
tak pokud bude mít obrázek jiný poměr stran, tak ho budeš vždy deformovat.
Když bude mít poměr stran stejný
(prostor: width) / (prostor: height) == (obr: width) / (obr: height), tak ho jenom zmenšíš.

Úprava takových rozměrů je snadná.
$new_height = $old_height / $old_width * $new_width;   
//$new_width je taková, jakou chceš a $new_height se dopočítá.

Vaše odpověď


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0