I'm trying to display resized images. Locations of images are fetched from
database. The problem is that with the following code, I get only the first
image displayed:
[PHP]
<?php
header('Content-type: image/jpeg');
$link = mysql_connect(' localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db ("proba1");
$query='select lokacija from galerija';
$result=mysql_q uery($query);
$new_width = 200;
$new_height = 150;
while($filename =mysql_fetch_ar ray($result)){
for($i=0;$i<=co unt($filename); $i++){
list($width, $height) = getimagesize($f ilename[$i]);
$image_p = imagecreatetrue color($new_widt h, $new_height);
$image = imagecreatefrom jpeg($filename[$i]);
imagecopyresamp led($image_p, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
imagejpeg($imag e_p, null, 100)."\n";
imagedestroy($i mage);
imagedestroy($i mage_p);
}
}
[/PHP]
With the next code in the same for loop I get all of the images, but
ofcourse not resized:
[PHP]
....
echo "<table>";
echo"<tr><td><i mg src=$filename[$i]></td></tr>";
echo "</table>";
....
[/PHP]
So I guess the problem is in image functions, but I don't know how to solve
it. Any suggestion is welcome :)
Tnx,
Dejan
database. The problem is that with the following code, I get only the first
image displayed:
[PHP]
<?php
header('Content-type: image/jpeg');
$link = mysql_connect(' localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db ("proba1");
$query='select lokacija from galerija';
$result=mysql_q uery($query);
$new_width = 200;
$new_height = 150;
while($filename =mysql_fetch_ar ray($result)){
for($i=0;$i<=co unt($filename); $i++){
list($width, $height) = getimagesize($f ilename[$i]);
$image_p = imagecreatetrue color($new_widt h, $new_height);
$image = imagecreatefrom jpeg($filename[$i]);
imagecopyresamp led($image_p, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
imagejpeg($imag e_p, null, 100)."\n";
imagedestroy($i mage);
imagedestroy($i mage_p);
}
}
[/PHP]
With the next code in the same for loop I get all of the images, but
ofcourse not resized:
[PHP]
....
echo "<table>";
echo"<tr><td><i mg src=$filename[$i]></td></tr>";
echo "</table>";
....
[/PHP]
So I guess the problem is in image functions, but I don't know how to solve
it. Any suggestion is welcome :)
Tnx,
Dejan
Comment