getimagesize

Status
Niet open voor verdere reacties.

Kevichill010

Gebruiker
Lid geworden
20 mrt 2013
Berichten
20
Hallo daar,
Ik ben bezig met een upload script die de gegevens van de fotos in mijn database zet en vervolgens eruit laden om alles weer te geven ,
alles werkte tot ik wat aanpassingen deed zoals getimagesize om ervoor te zorgen dat de fotos die weer gegeven worden dezelfde grote hebben i.p.v verschillende fotos met verschillende maten .
dit heb ik gedaan met :
Code:
<?php
$image_path = "upload/" .$row['location']."";
list($width, $height, $type, $attr)= getimagesize($image_path); 
//specify what percentage you are resizing to
$percent_resizing = 30;
$new_width = round((($percent_resizing/100)*$width));
$new_height = round((($percent_resizing/100)*$height));

// vervolgens bij het ophalen 
echo '<p><img src="'.$image_path.'" height="'.$new_height.'" width="'.$new_width.''.$row['location'].'"></p>';
?>

Het werkt wel alleen word er nu nog maar 1 foto weergegeven i.p.v alle die opgeslagen staan in de database, en die krijg ik niet opgelost momenteel even , dus bij deze suggesties ?

en ik wil graag 4 records per rij laten weergeven i.p.v random fotos om een rij ,
na wat zoeken en lezen ben ik hierbij gekomen en vroeg me af of dit goed genoeg is om te gebruiken om 4 records op een rij te laten zien , misschien iemand suggesties en of ideeén?
Code:
<?php 
        include_once("config.php");
        $result=mysql_query("SELECT * FROM photos");
        $count = 0;
        while($res=mysql_fetch_array($result))
        {
            if($count==3) //three images per row
            {
               print "</tr>";
               $count = 0;
            }
            if($count==0)
               print "<tr>";
            print "<td>";
            ?>
                    <?php echo $res['caption'];?></p>



                    <img src="<?php echo $res['location'];?>"/>



                <?php
            $count++;
            print "</td>";
        }
        if($count>0)
           print "</tr>";
        ?>

B.v.d
Kevin.
 
Dit kan niet de gehele code zijn:
PHP:
<?php
$image_path = "upload/" .$row['location']."";
list($width, $height, $type, $attr)= getimagesize($image_path); 
//specify what percentage you are resizing to
$percent_resizing = 30;
$new_width = round((($percent_resizing/100)*$width));
$new_height = round((($percent_resizing/100)*$height));

// vervolgens bij het ophalen 
echo '<p><img src="'.$image_path.'" height="'.$new_height.'" width="'.$new_width.''.$row['location'].'"></p>';
?>
 
nee klopt ,
Code:
<style type="text/css">
<!--
.ed{
border-style:solid;
border-width:thin;
border-color:#00CCFF;
padding:5px;
margin-bottom: 4px;
}
#button1{
text-align:center;
font-family:Arial, Helvetica, sans-serif;
border-style:solid;
border-width:thin;
border-color:#00CCFF;
padding:5px;
background-color:#00CCFF;
height: 34px;
}
#imagelist{
border: thin solid silver;
float:left;
padding:5px;
width:auto;
margin: 0 5px 0 0;
}
p{
margin:0;
padding:0;
text-align: center;
font-style: italic;
font-size: smaller;
text-indent: 0;
}
#caption{
margin-top: 5px;
}
img{
height: 225px;
}
-->
</style>
<?php
include('upload/config.php');
$result = mysql_query("SELECT * FROM photos");
while($row = mysql_fetch_array($result))

$image_path = "upload/" .$row['location']."";
list($width, $height, $type, $attr)= getimagesize($image_path); 
//specify what percentage you are resizing to
$percent_resizing = 30;
$new_width = round((($percent_resizing/100)*$width));
$new_height = round((($percent_resizing/100)*$height));
{
echo '<div id="imagelist">';
echo '<p><img src="'.$image_path.'" height="'.$new_height.'" width="'.$new_width.''.$row['location'].'"></p>';
echo '<p id="caption">'.$row['caption'].' </p>';
echo '</div>';
}
?>
 
Laatst bewerkt:
Kijk nu is je fout pas zichtbaar, zo moet het zijn (het php gedeelte):

PHP:
include('upload/config.php');
$result = mysql_query("SELECT * FROM photos");
while($row = mysql_fetch_array($result))
{
	$image_path = "upload/" .$row['location']."";
	list($width, $height, $type, $attr)= getimagesize($image_path); 
	//specify what percentage you are resizing to
	$percent_resizing = 30;
	$new_width = round((($percent_resizing/100)*$width));
	$new_height = round((($percent_resizing/100)*$height));

	echo '<div id="imagelist">';
	echo '<p><img src="'.$image_path.'" height="'.$new_height.'" width="'.$new_width.''.$row['location'].'"></p>';
	echo '<p id="caption">'.$row['caption'].' </p>';
	echo '</div>';
}
 
Laatst bewerkt:
Kijk nu zie ik weer alle records . thanks!,
alleen zie ik nu wel dat mijn images niet allemaal dezelfde size hebben wat wel de bedoeling in principe is,
of doe ik dat op een verkeerde manier nu ?
 
Eigenlijk doe je dit idd verkeerd, dit is onzin:
PHP:
   $percent_resizing = 30;
    $new_width = round((($percent_resizing/100)*$width));
    $new_height = round((($percent_resizing/100)*$height));

Je kan ook niet moeilijk doen:

PHP:
include('upload/config.php');
$result = mysql_query("SELECT * FROM photos");
while($row = mysql_fetch_array($result))
{
    $image_path = "upload/" .$row['location']."";
    echo '<div id="imagelist">';
    echo '<p><img src="'.$image_path.'" height="150px" width="150px"></p>';
    echo '<p id="caption">'.$row['caption'].' </p>';
    echo '</div>';
}

height="150px" width="150px"
In dit stukje html staat de grote zo als je ziet
 
Laatst bewerkt:
ja inderdaad zit ook al te kijken waarom ik zo stom moeilijk loop te doen als het simpel weg met width en height tag kan .. , dus t hele getimagesize gedoe is onzin inderdaad,. Iedergeval thanks in een doeloze code oplossing haha ., alleen nog een vraag
hoe ken ik het aanpakken om maar 4 records per rij te laten zien i.p.v dat alles nu automatisch naast elkaar komt zover t scherm het toelaat.

wat ik nu heb :
PHP:
<?php
include('upload/config.php');
$amount_per_row = 4;
$i = 1;
$result = mysql_query("SELECT * FROM photos");
while($row = mysql_fetch_array($result))

// If this is the first record of a row, print a row beginner
  if($i-1 % $amount_per_row == 0) {
            echo "<tr>";
  }
  // Print the record
{
    $image_path = "upload/" .$row['location']."";
    
 
    echo '<div id="imagelist">';
    echo '<p><img width="150" height="150" src="'.$row['location'].'  "></p>';
    echo '<p id="caption">'.$row['caption'].' </p>';
    echo '</div>';
}

 // If this is the last record of a row, print a row end
  if($i % $amount_per_row == 0) {
            echo "</tr>";
  }
  $i++

// Make sure a row end is printed if there are less records than the amount per row.
	if($i % $amount_per_row != 1) {
  echo "</tr>" 
	}
?>

alleen krijg ik error i.v.m de laatste if($i %amount_per_row !=1)
: Parse error: syntax error, unexpected T_IF in H:\root\gall\index.php on line 72
 
Laatst bewerkt:
Alstublieft,

PHP:
<?php
include('upload/config.php');
$amount_per_row = 4;
$count = 0;
$result = mysql_query("SELECT * FROM photos");
while($row = mysql_fetch_array($result))

  // Print the record
{
    $image_path = "upload/" .$row['location']."";
    echo '<div id="imagelist">';
    echo '<p><img width="150" height="150" src="'.$row['location'].'  "></p>';
    echo '<p id="caption">'.$row['caption'].' </p>';
    echo '</div>';
	if($count % $amount_per_row == 3){ echo '</br>';}
	$count++;
}
 

?>
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan