473,396 Members | 1,998 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,396 software developers and data experts.

image gallery- image not displaying

116 100+
ok i have a folder made on the server and uploaded image files to it...the link to the image file or rather the path to the image is uploaded in the database in 'image_path' , now i want that the system read the path and resize it to generate a thumbnail and display it on the browser.

but the code is showing blank

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3.  
  4. // generating a array with image paths 
  5.  
  6. $query_images = "SELECT image_path FROM userfolders" ;
  7. $result_images = mysql_query($query_images);
  8. confirm_query($result_images);
  9.  
  10. while ($record_images = mysql_fetch_assoc($result_images)) {
  11.           $image_list[] = $record_images['image_path'] ;
  12.  
  13. ?>
  14.  
  15. <?
  16. // generating a thumbnail 
  17.  
  18. $thumb_height = 100;
  19.  
  20. for ($i=0,$i<count($image_list),$i+)
  21. {
  22.  
  23. $filename = $image_list[$i];
  24. list($width, $height) = getimagesize($filename);
  25. $ratio = ($height/$width);
  26. $newheight = $thumb_height;
  27. $newwidth = ($thumb_height/$ratio);
  28.  
  29. $thumb = imagecreatetruecolor($newwidth, $newheight);
  30. $source = imagecreatefromjpeg($filename);
  31.  
  32. $thumb_image = imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  33.  
  34.   // displaying thumbnail
  35.  
  36. $thumbnail =  imagejpeg($thumb_image);
  37.  
  38. echo $thumbnail;
  39.  
  40.  
  41.  
  42.  
  43. ?>
  44.  
  45.  
Plz tell me wat i m doing wrong what lines i need to add or remove.

the image path is like d:/wamp/www/images/apple.jpg
May 12 '09
53 4362
angelicdevil
116 100+
i took the static values as follwing code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // generating a array with image paths
  4.  
  5.  
  6.  
  7. // generating a thumbnail
  8. $thumb_height = 100;
  9. $filename = "http://bytes.com/images/apple.jpg";
  10. list($width, $height) = getimagesize($filename);
  11.         $ratio = ($height/$width);
  12.         $newheight = $thumb_height;
  13.         $newwidth = ($thumb_height/$ratio);
  14.         echo  $newwidth;
  15.         $thumb = imagecreatetruecolor($newwidth, $newheight);
  16.         $source = imagecreatefromjpeg($filename);
  17.  
  18.         $thumbnail= imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  19.  
  20. // displaying thumbnail
  21.  
  22. header('Content-type: image/jpeg');
  23. imagejpeg($thumb);
  24. imagedestroy($thumb); 
  25.  
  26.  
  27.  
  28.  
  29.  
  30. ?>
  31.  
  32.  
i get the output as
http://localhost/test.php
cant seem to figure out y as phpinfo shows gd is enabled
May 28 '09 #51
Atli
5,058 Expert 4TB
Two problems there...
  1. To use URLs in that manner, the allow_url_fopen directive must be enabled.
  2. The URL 'http://bytes.com/images/apple.jpg' isn't a image.
Try an absolute file system path instead.

Anyways, you need to debug the code... find out exactly where it is failing.
Check the return values of each of the function calls. Make sure they are actually valid. (See my first post.)
May 28 '09 #52
angelicdevil
116 100+
code 1 :-
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // generating a array with image paths
  4.  
  5. $query_images = "SELECT image_path,image_name FROM userfolders" ;
  6. $result_images = mysql_query($query_images);
  7. confirm_query($result_images);
  8.  
  9. while ($record_images = mysql_fetch_assoc($result_images)) {
  10.           $file = $record_images['image_name'] ;
  11.           $dirname = $record_images['image_path'] ;
  12.  
  13.  
  14. // generating a thumbnail
  15. $thumb_height = 100;
  16. $filename = $dirname."/".$file;
  17. list($width, $height) = getimagesize($filename);
  18.         $ratio = ($height/$width);
  19.         $newheight = $thumb_height;
  20.         $newwidth = ($thumb_height/$ratio);
  21.         echo  $newwidth;
  22.  $thumb = imagecreatetruecolor($newwidth, $newheight);
  23.  echo $thumb ;
  24.  $source = imagecreatefromjpeg($filename);
  25.  echo $source;
  26.  $thumbnail= imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  27.  echo $thumbnail;
  28.  
  29.  header('Content-type: image/jpeg');
  30. imagejpeg($thumbnail);
  31.  
  32. }
  33. ?>
  34.  
the o/p is as follows
109, resource id#10, resource id #12, 1
it seems the code is failing at imagejpeg command as soon as i put

code 2 :-
Expand|Select|Wrap|Line Numbers
  1. header('Content-type: image/jpeg');
  2. imagejpeg($thumb);
  3. imagedestroy($thumb); 
  4.  
the o/p displays only http://localhost/test.php
even the values of new width thumb source and thumbnail do not get displayed when the code 2 is inserted into code 1
Jun 1 '09 #53
Atli
5,058 Expert 4TB
Your code is failing because of all the echos in your code.

If you plan to output an image, you must only output the image data, or the image will be corrupted and the browser will not be able to display it.

In cases like these, you should only print debug messages if there is a problem.Use if statements to check the variables and stop the execution with an error message if it doesn't check out.
(See the way I use die() in the example in my first post)

But don't print debug messages when outputting binary data unless there is a problem.

P.S.
You are passing the wrong variable to the imagejpg function in your first code.
It should be getting $thumb rather than $humbnail.
Jun 1 '09 #54

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: nick | last post by:
After spending many hours trying to find a simple looking, fast,dynamic php photo-gallery for my digital pictures, I decided to code a my own. Once installed, all you have to do is drop a new...
2
by: Daniel Kelly \(AKA Jack\) | last post by:
Hi! I'm searching for a Photo Gallery software package (like Coppermine and Gallery) that works, from the ground up, like a database-driven app. In other words, I want a gallery which entirely...
1
by: Simone Winkler | last post by:
Hello, I don't know if my question is out of topic...so I apologize if I am. I use the coppermine picture gallery for my web (actually I want to use it but the server doesn't seem to have GD...
10
by: Captain Ranger McCoy | last post by:
Hello! Suppose I have ten servers at ten ips: x.x.x.1 x.x.x.2 x.x.x.3 x.x.x.4 and so on Each server hosts 100+ photo galleries, all under a single domain name,
5
by: Fred | last post by:
I've written a number of "image gallery" pages before, but I'm trying to do something a little different. All the images are rectangular (these are just pictures from my camera), and the...
1
by: desjardins.daniel | last post by:
Hi ! Excuse my english, i'm a french canadien... So here my message : I have put on my site a photo gallery and at the right a nav menu. This menu has a red dot visible want someone is passing...
1
by: Throw | last post by:
G'day everyone I'm looking for a simple photo gallery script in PHP (or Perl), but not too simple. I have tried several photo gallery scripts in either language and I have found that they are...
11
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. ...
6
omerbutt
by: omerbutt | last post by:
hi all i am using a slide picture gallery provided by http://smoothgallery.jondesign.net/showcase/gallery/ the gallery is working fine but only if i try to make 2 slide shows on the same page it...
0
nomad
by: nomad | last post by:
Hello Everyone. I founded an Flash and xml photo gallery. It works but I took it to another step What I want is to have six different galleries in one Flash file. I figure out how to do that but ...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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,...
0
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...
0
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...
0
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,...

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.