SitePoint Sponsor

User Tag List

Results 1 to 25 of 25
  1. #1
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP photo gallery suggestions

    Hi

    I wanted to ask all of you what PHP photo galleries do you recommend. I know I can search for them on google but they doesn't help me with what people have actually tried and proven to work. I could also create my own photo gallery although I only have a few years of PHP experience under my belt so it would take me some time to do.

    SO I'm looking for suggestions or advice of how to go about it.

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have found that site and was wonder how good it is. Do you have experience with using it?

  4. #4
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,357
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    You have to decide what you want; personaly I would not use that one as there are way to many features that I would never use.

    I made my own http://www.rubble.info/gallery/gallery.php but that is because I could not find anything to fit exactly what I wanted - I keep meaning to do some more work on it but never find the time.

  5. #5
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes that's the only reason I haven't jumped right into the "gallery" program. It seems to be a little bloated for my needs. I looked at your gallery very nice. It seems you used the $_POST vars instead of the $_GET vars. Any reason for that?

    I also found your snippets sections thanks very much for the work you have done. They should help me learn how to resize images in upload.

  6. #6
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    CA
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    4images

  7. #7
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,357
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    Thanks for the coments lespaulsf I like my gallery although it could do with some more work. I use $_POST instead of $_GET as it gives a nicer URL but its not to good if somebody wants to bookmark the page.
    This is another version I have done which uses the $_POST and .htaccess to modify the URL to make it SOE friendly http://www.salmonsbros.co.uk/services.php

    As I said I would decide what features I wanted e.g. Database or no database - upload through a form or on the PC.
    Out of interest my personal site does not use a database but uses Glob to read a directory. The second uses a database as I want to tie the images and text together, as well as some of the images to each other.

    I am glad you found the snippets interesting; I do not use most of them myself but just try them out !

  8. #8
    SitePoint Enthusiast mexabet's Avatar
    Join Date
    Jul 2008
    Location
    mexabet.biz
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's always better to create a customized gallery to serve your needs. You can equally hire someone to do it, as you don't have time. I believe it won't cost much. I'm developing one at the moment, but stuck somehow.
    The Best Is Yet To Come!

  9. #9
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by steveeyes View Post
    4images
    THanks very much !Although I don't read German and from what I can tell this piece of software looks to be way overkill for what I want it to do.

  10. #10
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rubble View Post
    This is another version I have done which uses the $_POST and .htaccess to modify the URL to make it SOE friendly http://www.salmonsbros.co.uk/services.php

    As I said I would decide what features I wanted e.g. Database or no database - upload through a form or on the PC.
    Out of interest my personal site does not use a database but uses Glob to read a directory. The second uses a database as I want to tie the images and text together, as well as some of the images to each other.
    I like the second one also. Although I though .htaccess and modify rewrite make a link like:

    http://webpage.com?album=trips&image=4

    into

    http://webpage.com/album/4

    Or something like that. I need to learn how to do that.

    Anyway your gallery has a query string.

    What I want is to have Categories and then store the image name and text associated with the image in a table. The possibly have one folder of pictures for each category. That's my initial thought process.

  11. #11
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mexabet View Post
    It's always better to create a customized gallery to serve your needs. You can equally hire someone to do it, as you don't have time. I believe it won't cost much. I'm developing one at the moment, but stuck somehow.
    It looks like I'm leaning towards creating my own. Although its not the time so much its more the knowledge. I think I have most of it down but thought maybe a ready made Gallery might be easier to implement.

  12. #12
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any other advice or suggestions to creating a photo gallery.

    Also Rubble did you have a chance to let me know what you mean about the .htaccess? Is this better for SEO also more friendly?

  13. #13
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,357
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    Using .htaccess to modify the URL is supposed to be good as the URL looks like a normal page not a dynamic one.

    This will get you started with the upload part - you need Imagemagick installed for this. If you are having user input as well as your own you need some validation.

    Form ( upload.php ):
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"
    >
    <
    html>
    <
    head>
          <
    title>Select the image to upload.</title>
          <
    link rel='stylesheet' href='admin_layout.css' type='text/css'>
    </
    head>

    <
    body>

    <
    div id="contents ">
    <
    table>
        <
    form method="POST" action="process.php" enctype="multipart/form-data">
        <
    tr><td>Text to use with the photo:</td><td><textarea name="text" cols="50" rows="5"></textarea></td></tr>
        <
    tr><td>Photo to use:</td><td><input type="file" name="photos"><br />MAXIMIUM PHOTO SIZE 2Mb</td></tr>
        <
    tr><td>Section to put photo into:</td><td>
            <
    select name="section">
            <
    option value="1">Section 1</option>
            <
    option value="2">Section 2</option>
            </
    select></td></tr>
        <
    tr><td colspan="2">
        <
    input type="submit" name="submit" value="Upload photo">
        </
    form>
    </
    td></tr></table>
    </
    div>
    </
    body></html
    Database connection file ( connect.php ):
    PHP Code:
    <?php
    //Mysql settings

    $host'localhost';
    $username '';
    $password '';
    $database 'test';

    $conn = @mysql_connect"localhost""$username""$password);

    if (!
    $conn) die ("Could not connect MySQL");

    @
    mysql_select_db$database,$conn ) or die ( "Could not open database" );

    // Table name - only need to change it here rather than 2 or 3 other places
    $table "lespaulsf";

    ?>
    Databse sql:
    PHP Code:
    CREATE TABLE `lespaulsf` (
      `
    image_IDsmallint(5NOT NULL auto_increment,
      `
    descriptiontext collate latin1_general_ci NOT NULL,
      `
    imagevarchar(50collate latin1_general_ci NOT NULL,
      `
    sectionvarchar(20collate latin1_general_ci NOT NULL,
      
    PRIMARY KEY  (`image_ID`)
    ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=
    Process image ( process.php ):
    PHP Code:
    <?php
    // Include the database connect file      
    include('connect.php');

    // Display the data passed to the process - Comment out when publishing
    //print_r( $_POST ); echo '<pre>'; print_r( $_FILES ); echo '</pre>'; 

    // If file size was to large display an error
    if( $_FILES['photos']['error'] == ){
    echo 
    "<p class=\"note\">Photo ".$_FILES['photos']['name'].". was to large and not uploaded</p>"; } 

    // setup the variables from the data posted
    $description $_POST['text'];
    $section $_POST['section']; 

    // Get the time to use in the new file name 
    $new_name time();

    // Get the tempory image name and put into a variable
    $value $_FILES['photos']['tmp_name'];

    // New thumbnail name
    $thumb "thumbs/$new_name.jpg";

    // New photo name
    $photo "photos/$new_name.jpg";

    // Resize and add the border
    exec("convert $value -strip -resize x100 -bordercolor black -border 1x1 $thumb "); 

    // Large image with border
    exec("convert $value -strip -resize x600 -bordercolor black -border 1x1 $photo ");

    // Check the photo was uploaded  and put the data into the database
    if ( file_exists$photo )) {
    mysql_query("INSERT INTO $table ( description, image, section )
    VALUES( '
    $description', '$new_name', $section ) ") or die(mysql_error());

    mysql_close($conn);

    header "Location: upload.php" ); 
    }

    // If the photo was not uploaded diplay an error
    else { die("<p>The file was not uploaded please go back and try again</p>"); }
    ?>
    Display the image from section 1 ( display.php )
    PHP Code:
    <?php
    <?php

    include 'connect.php';

        
    $result = @mysql_query("SELECT * FROM $table WHERE section = '1' ") or die ( mysql_error() );
        while ( 
    $row = @mysql_fetch_array$result )) {

    // Display the image
        
    $display_image "thumbs/".$row['image'].".jpg";
            if ( 
    file_exists$display_image )) {
                
    $size getimagesize$display_image );
                echo 
    "<a href=\"photos/".$row['image'].".jpg\">\n
                <img src=\""
    .$display_image."\" ".$size[3]." alt=\"image number ".$row['image']."\" border=\"0\"/></a>\n";
                echo 
    $row['description']."<br>";
    }}
                
    ?>
    You will need a folder called thumbs and photos in the same folder as the code. Once you get it working you can move things around. I use different folders for different sections but I have left it simple for now.

    You can expand this to upload multiple images, add different effects to the images etc.

  14. #14
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,357
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    Out of interest on my personal site I do not use a database but have the different catagory photos in different folders and use a text file for each image. So you do not have to use a database to do what you want.

    I belive it can also be done using an XML file to keep track of all the information although I have not tried that yet.

  15. #15
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow thanks very much! This is defiantly a good start. I will work on it and see what I can come up with. I will most likely use a db for storing image name, and description. I was wondering what the "section" field was for but figured it out. This is how you keep them in separate albums correct?

    I currently use the GD image framework for my images. Is there a way to do the same sort of thing with GD or can I run GD and Imagemagick on the same server at the same time?

  16. #16
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,357
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    Sorry I should have used catagory not section !

    Yes you can use GD and Imagemagick on the same server. GD comes with php and if you have a Unix/linux server it COULD have Imagemagick installed as it is an option of the install.
    Some code to check your setup here: http://www.rubblewebs.co.uk/imagemag...ver/server.php

    The thing about Imagemagick is it has lots more options than GD; you can convert from over 100 image formats to over 100 image formats with one line of code unlike GD where you have to use a switch command or similar for every image format you may work with.

    Resizing an image with GD and Imagemagick retaining the aspect ratio:
    PHP Code:
    GD
    <?php
    // Temporary upload image name
    $original_image '../original_images/flowers.jpg';
    // Get the image dimensions
    $size=GetImageSize$original_image );
    // Maximum image width
    $max_width "100";
    // Maximum image height
    //$max_height = "100";

    $ratio 100/$size[0];
    $max_height $size[1]*$ratio;

    // Resize the image and save        
    $src_img ImageCreateFromJPEG$original_image );
    $thumbnail ImageCreateTrueColor$max_width$max_height );
    ImageCopyResampled$thumbnail$src_img0000$max_width$max_height$size[0],$size[1] );
    ImageJPEG$thumbnail'flowers_GD.jpg' );
    ImageDestroy$thumbnail );
    ?> 

    IM:
    <?php
    // Temporary upload image name
    $original_image '../original_images/flowers.jpg';
    // Maximum image width
    $max_width "100";
    // Maximum image height
    $max_height "100";
    // Resize the image and save
    exec("convert $original_image -thumbnail $max_widthx$max_height flowers_IM.jpg");
    ?>
    As you can see there is a lot less code with Imagemagick; there are some negative things as you need Safe mode off and as you are calling an external program you need to make sure you sanitize all user input properly.
    There can be a speed issue as Imagemagick is calling an external program but unless you are uploading loads of photos it is not worth worrying about. You can speed up Imagemagick by using an API - I use exec with the command line code as I prefer it.

  17. #17
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks very much for your help so far. Since I use hostgator for my host I don't think that would allow Safe mode off. I will most likely go the GD route since I have worked with it before. Although I can see its more work. Maybe down the road I will be able to learn more about ImageMagick.
    Last edited by lespaulsf; Nov 20, 2008 at 08:55. Reason: spelling

  18. #18
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,357
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    I looked at moving to Hostgator and they did have Imagemagick installed when I asked about it.

    Run this and see if you get an output of the IM version:
    PHP Code:
    <?php
    echo "<pre>";
    system("convert -version");  
    echo 
    "</pre>";
    ?>
    The GD code is longer but I suppose once it is written it does not need changing.

  19. #19
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I went to hostgator and see that they do support IMagemagick. The only concern I have is that safemode is off to use it as you stated. What kind of security issues would there be for this? There sure is alot less code using it vs GD so I'm a little interested.

  20. #20
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,357
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    You will have to find the info about safe mode as I am not sure now. I did know once when I started but that was a while ago.
    If Hostgator supports Imagemagick safe mode might be off already ?

  21. #21
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok so I've got quite a long way in the process of the image gallery. Although I have ran into a small issue. From what I understand to do any resizing of images PHP has to know where its located. Is there a way to use the tmp_name instead?

    When I use getimagesize() function is seems to need to know where the files in located. This works fine if I upload the file and then move it to a folder. I then reference that folder and give it to the getimagesize(). I can do it this way but then I have to go and manually delete the orginal image uploaded that might be 2MB and 1280 X 1024. As you can guess this would get really old.

  22. #22
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone have any advice or help on this?

  23. #23
    SitePoint Enthusiast mexabet's Avatar
    Join Date
    Jul 2008
    Location
    mexabet.biz
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use something similar to this in my configuration file:
    PHP Code:
    <?php
    // APP_ROOT will always be set to two directories up from the location of this file
    define('APP_ROOT'dirname(dirname(__FILE__)) . '/');

    // An album can have an image used as thumbnail
    // we save the album image here
    define('ALBUM_IMG_DIR'APP_ROOT 'myimages/album/');

    // All my images inside an album are stored here
    define('GALLERY_IMG_DIR'APP_ROOT 'myimages/gallery/');

    // When you upload an image, its thumbnail will be created automatically
    // Set the thumbnail width in pixel. The height will
    //adjust proportionally
    define('THUMBNAIL_WIDTH'180);
    ?>
    Then create a directory called thumbnail under gallery. This means it should be accessed though YourApplication/myimages/gallery/thumbnail

    In your SQL image table you need to place this: `im_thumbnail` VARCHAR(60) NOT NULL,

    Quote Originally Posted by lespaulsf View Post
    Anyone have any advice or help on this?
    The Best Is Yet To Come!

  24. #24
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,357
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    If you are using the upload form I posted the tmpory image is:
    PHP Code:
    // Get the tempory image name and put into a variable
    $value $_FILES['photos']['tmp_name']; 
    So you should be able to use
    PHP Code:
    $size getimagesize$value ); 

  25. #25
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok so I started working on my own photo gallery. Right now I can upload multiple images. I just added a option for the person to add desc text to each image if they want. Although I'm for sure how to process the same time as the images. Essetional I want to put the image path and the desc text into the db at the same time. I need a loop or something but i can't get it to work.

    I know that in images I use image[] but if I try to put that same thing in the form for a text field like so desc[] it doesn't work. Does anyone have suggestions on how to do this?


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
  •