473,386 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Image displaying

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_query($query);
$new_width = 200;
$new_height = 150;
while($filename=mysql_fetch_array($result)){

for($i=0;$i<=count($filename);$i++){

list($width, $height) = getimagesize($filename[$i]);
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename[$i]);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
imagejpeg($image_p, null, 100)."\n";
imagedestroy($image);
imagedestroy($image_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><img 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
Oct 8 '06 #1
5 2127
It looks as if you are creating the second image, but not saving it anywhere.

This generates an image: imagejpeg($image_p, null, 100)."\n";

But what about $image? You do a copyresampled then destroy it. If you want
to save the image, pass the second argument to imagejpeg.
ljuljacka wrote:
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_query($query);
$new_width = 200;
$new_height = 150;
while($filename=mysql_fetch_array($result)){

for($i=0;$i<=count($filename);$i++){

list($width, $height) = getimagesize($filename[$i]);
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename[$i]);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
imagejpeg($image_p, null, 100)."\n";
imagedestroy($image);
imagedestroy($image_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><img 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

Oct 8 '06 #2
The thing I'm trying to get is to display images as thumbnails without
actually saving them, and the script does that but only with the first
image.
When I echo $filename[$i] inside the for loop it displays all file
locations.
When I removed imagedestroy() from script, it still does the same...
So the problem is displaying other images.

If this answer is funny it's because I don't know if I understood you
correctly :)

"ZabMilenko" wrote in message :
>It looks as if you are creating the second image, but not saving it
anywhere.

This generates an image: imagejpeg($image_p, null, 100)."\n";

But what about $image? You do a copyresampled then destroy it. If you
want to save the image, pass the second argument to imagejpeg.


Oct 8 '06 #3
Here is what I am seeing:
while($filename=mysql_fetch_array($result))
{

for($i=0;$i<=count($filename);$i++)
{
// loop thru a bunch of files

list($width, $height) = getimagesize($filename[$i]);
// find out how big it is

// Make an new image IN MEMORY
$image_p = imagecreatetruecolor($new_width, $new_height);

// make an image IN MEMORY from the original
$image = imagecreatefromjpeg($filename[$i]);
// Paint the image as a thumbnail IN MEMORY
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
// Send the new image to the browser
imagejpeg($image_p, null, 100)."\n";
imagedestroy($image);
imagedestroy($image_p);
}

// Repeat
}

The problem is you can only send one image per request. That is ONE image
between header("content-type ...") and imagejpeg()

You can make all you want, but only the first will go to the browser. The
rest is as useless as spam.

So you need to dump the thumbnails to disk and load them another way.
ljuljacka wrote:
The thing I'm trying to get is to display images as thumbnails without
actually saving them, and the script does that but only with the first
image.
When I echo $filename[$i] inside the for loop it displays all file
locations.
When I removed imagedestroy() from script, it still does the same...
So the problem is displaying other images.

If this answer is funny it's because I don't know if I understood you
correctly :)

"ZabMilenko" wrote in message :
>It looks as if you are creating the second image, but not saving it
anywhere.

This generates an image: imagejpeg($image_p, null, 100)."\n";

But what about $image? You do a copyresampled then destroy it. If you
want to save the image, pass the second argument to imagejpeg.


Oct 8 '06 #4
Yes, I get it now...tnx for your help. I guess I have some work to do :)
"ZabMilenko" <za********@hotmail.comwrote in message
news:Sr***********@newsfe03.lga...
Here is what I am seeing:
while($filename=mysql_fetch_array($result))
{

for($i=0;$i<=count($filename);$i++)
{
// loop thru a bunch of files

list($width, $height) = getimagesize($filename[$i]);
// find out how big it is

// Make an new image IN MEMORY
$image_p = imagecreatetruecolor($new_width, $new_height);

// make an image IN MEMORY from the original
$image = imagecreatefromjpeg($filename[$i]);
// Paint the image as a thumbnail IN MEMORY
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
// Send the new image to the browser
imagejpeg($image_p, null, 100)."\n";
imagedestroy($image);
imagedestroy($image_p);
}

// Repeat
}

The problem is you can only send one image per request. That is ONE image
between header("content-type ...") and imagejpeg()

You can make all you want, but only the first will go to the browser. The
rest is as useless as spam.

So you need to dump the thumbnails to disk and load them another way.
ljuljacka wrote:
>The thing I'm trying to get is to display images as thumbnails without
actually saving them, and the script does that but only with the first
image.
When I echo $filename[$i] inside the for loop it displays all file
locations.
When I removed imagedestroy() from script, it still does the same...
So the problem is displaying other images.

If this answer is funny it's because I don't know if I understood you
correctly :)

"ZabMilenko" wrote in message :
>>It looks as if you are creating the second image, but not saving it
anywhere.

This generates an image: imagejpeg($image_p, null, 100)."\n";

But what about $image? You do a copyresampled then destroy it. If you
want to save the image, pass the second argument to imagejpeg.

Oct 8 '06 #5
ZabMilenko said the following on 08/10/2006 14:55:
Here is what I am seeing:
while($filename=mysql_fetch_array($result))
{

for($i=0;$i<=count($filename);$i++)
{
// loop thru a bunch of files

list($width, $height) = getimagesize($filename[$i]);
// find out how big it is

// Make an new image IN MEMORY
$image_p = imagecreatetruecolor($new_width, $new_height);

// make an image IN MEMORY from the original
$image = imagecreatefromjpeg($filename[$i]);
// Paint the image as a thumbnail IN MEMORY
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
// Send the new image to the browser
imagejpeg($image_p, null, 100)."\n";
imagedestroy($image);
imagedestroy($image_p);
}

// Repeat
}

The problem is you can only send one image per request. That is ONE image
between header("content-type ...") and imagejpeg()

You can make all you want, but only the first will go to the browser.
The rest is as useless as spam.

So you need to dump the thumbnails to disk and load them another way.
Or have the script only output one image, and call it N times, i.e.:
<img src="script.php?img=1">
<img src="script.php?img=2">
<img src="script.php?img=3">
<img src="script.php?img=4">
Oct 8 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tjerk | last post by:
Hello all, I have the script below to change an image depending on the date upto january it worked fine but then it just stopped working does anybody have an idea how I can make it work again or...
5
by: ken | last post by:
I had to reinstall Windows 2000 Pro and of course Access 2000. I HAD each record displaying a photo but now it does not show them. The WEIRD thing is that when I upload the database to my...
2
by: Al Reid | last post by:
Is it possible to display an image that is stored on the server as a TIFF image, on an ASP.Net page without the use of an add-in viewer? If so, could someone tell me how to do it? TIA -- Al...
2
by: pmud | last post by:
Hi, I am designing a simple ASP.NET web page. I have an image button. What I want to do is: when the cursor is over the image button, a drop down meny should display. This menu should have tabs...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
3
by: CD | last post by:
An application is logging faxes sent in SQL2000 image column type. I have found code on the net but what it is doing is prompting to save to local which is fine for single page image. Not good...
6
by: Jeff | last post by:
hi asp.net 2.0 I have a image (.jpeg) stored in sql server 2005 and now I want to display it on a webpage. So I created a webpage (Image.aspx) which just writes the buffer data to the...
3
by: brijesh1234 | last post by:
dear Sir/madam I am getting a problem while displaying a image from database Database : MSSQL2000 I have a table named “Image” having following fields as ImageId int Image Image
3
by: mvijayrkumar | last post by:
Hi to all.... Guys pls help me..... I have an image issue in RLDC while hosting my project on server.The image displays or works fine with the local system.But when hosted on server,both the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.