472,332 Members | 1,339 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,332 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 4221
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. ...
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. ...
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...
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...
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...
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...
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...
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...
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...
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.