473,749 Members | 2,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_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
Oct 8 '06 #1
5 2155
It looks as if you are creating the second image, but not saving it anywhere.

This generates an image: imagejpeg($imag e_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_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

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($imag e_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_ar ray($result))
{

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

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

// Make an new image IN MEMORY
$image_p = imagecreatetrue color($new_widt h, $new_height);

// make an image IN MEMORY from the original
$image = imagecreatefrom jpeg($filename[$i]);
// Paint the image as a thumbnail IN MEMORY
imagecopyresamp led($image_p, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
// Send the new image to the browser
imagejpeg($imag e_p, null, 100)."\n";
imagedestroy($i mage);
imagedestroy($i mage_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($imag e_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********@hot mail.comwrote in message
news:Sr******** ***@newsfe03.lg a...
Here is what I am seeing:
while($filename =mysql_fetch_ar ray($result))
{

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

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

// Make an new image IN MEMORY
$image_p = imagecreatetrue color($new_widt h, $new_height);

// make an image IN MEMORY from the original
$image = imagecreatefrom jpeg($filename[$i]);
// Paint the image as a thumbnail IN MEMORY
imagecopyresamp led($image_p, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
// Send the new image to the browser
imagejpeg($imag e_p, null, 100)."\n";
imagedestroy($i mage);
imagedestroy($i mage_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($imag e_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_ar ray($result))
{

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

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

// Make an new image IN MEMORY
$image_p = imagecreatetrue color($new_widt h, $new_height);

// make an image IN MEMORY from the original
$image = imagecreatefrom jpeg($filename[$i]);
// Paint the image as a thumbnail IN MEMORY
imagecopyresamp led($image_p, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
// Send the new image to the browser
imagejpeg($imag e_p, null, 100)."\n";
imagedestroy($i mage);
imagedestroy($i mage_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
4184
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 why it doesn't work? Thanks in advance Tjerk
5
1599
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 website...the image shows up! Is there a setting in Access that I need to chnage because of the reinstall? Thanks. Ken
2
3580
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 Reid
2
2074
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 which are images. What can be the C# code for this. Please help. Thanks
7
11638
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 is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
3
5828
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 for multiple page faxes. I have not been able to locate an example to load in the browser or how to handle multiple image in the one column. 1) Ideally it would be nice to display back in the browser since some may be multiple images. I am not...
6
2192
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 Response object. On Default.aspx I use this Image.aspx for displaying the image, but no image
3
2493
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
7732
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 images(One coming from DataSet and another from my project image folder) not displaying. Both images are having Type property External and the Values are given correspondingly.ie The One coming from Image Folder;using the Report Parameter ,the...
0
8997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9389
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6801
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.