SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    nyc
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    display image thumbnails

    Hi all

    I want to display the embedded thumbnails of jpg files.
    I have looked at the PHP Manual and found that

    exif_thumbnail($image_file);

    retreives the Thumbnail from a jpg or a Tiff, but if I use

    $image = exif_thumbnail($image_file);
    echo $image;

    PHP outputs the CODE of the image thumbnail, and does not display the actual image thumbnail.
    I have read that I should somehow 'send the mimetype information using the header() function', to actually display the thumbnail, so I looked at the header function in the PHP manual but didn't find any example of how I would use header to display a thumbnail.

    Can someone help me?

  2. #2
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to put this at the top of your page before outputting anything:

    PHP Code:
    $fileext 'jpg';
    header('Content-type: image/' $fileext); 

  3. #3
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    nyc
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did waht you suggested, and my page downloaded to my desktop instead of being displayed in the browser.
    I guess
    $fileext = 'jpg';
    header('Content-type: image/' . $fileext);
    means that the file this script is in is a jpg?

    What I want, is to display images thumnails in an html page. Not download them on the user desktop.

    Say if I index a folder containing jpg images, what I want to do is:

    PHP Code:
    foreach ($images as $image) {
        
    $thumbnail exif_thumbnail($image);
        echo 
    '<div>'.$thumbnail.'</div>';

    And the result would be all the thumnails displayed in the html page. But this doesn't work, because it does not display the thumbnails, it displays the code that constitute the thumbnail file.

    How can I display the thumbnails in an html page?

  4. #4
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need a thumbnail.php file:

    PHP Code:
    <?php

    header
    ('Content-type: image/jpeg');

    echo 
    exif_thumbnail($_GET['i']);

    ?>
    Then in the other page:

    PHP Code:
    foreach ($images as $image) {
        echo 
    '<div><img src="thumbnail.php?i='.$image.'" alt="" /></div>';


  5. #5
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    nyc
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! great! it all makes sense now, and it works.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •