Best way to implement a php image gallery?

Caporegime
Joined
12 Mar 2004
Posts
29,919
Location
England
Say I have a website that I want to put a couple of image galleries on, where thumbnails show first and then clicking brings up the full size image, is my best best bet to store the images in the websites file system and reference them from the database or to store the images in the database itself allowing me to backup the whole site content easily by just backing up the database?
 
Associate
Joined
10 Nov 2013
Posts
1,808
Depends on the requirements of your project, but in general I would store images in the file system and store a path to the images in the database. File systems are designed to store files, databases are designed to store data.
 

fez

fez

Caporegime
Joined
22 Aug 2008
Posts
25,802
Location
Tunbridge Wells
Yep, store images on the server and when you backup the site simple pull down that folder as well as a dump of the db. Its best if images are not stored in the db.
 
Caporegime
OP
Joined
12 Mar 2004
Posts
29,919
Location
England
What method do you guys use to deal with thumbnails and enlargements?

I was thinking of exporting all images from Lightroom at two different sizes with thumb/full appended to the name and then using php to switch between the two when clicked on?
 
Associate
Joined
7 Apr 2012
Posts
2,101
Location
Tampa Bay
What method do you guys use to deal with thumbnails and enlargements?

I was thinking of exporting all images from Lightroom at two different sizes with thumb/full appended to the name and then using php to switch between the two when clicked on?

PHP can generate thumbnails for you, do a google search and you'll find a ton of examples :)
 
Caporegime
Joined
18 Oct 2002
Posts
29,491
Location
Back in East London
You would want to generate the thumbnail once at upload time (or the first time that particular thumbnail is requested) rather than generate it new for each request. Especially if you are expecting any kind of load. :)

Certainly I'd argue to keep the images on the filesystem and not within the DB.
 

fez

fez

Caporegime
Joined
22 Aug 2008
Posts
25,802
Location
Tunbridge Wells
There are loads of image manipulation libraries out there that allow you to do things like image resizing, cropping, rotating etc. Its usually much easier to use one of these than try to use the built in php image manipulation classes directly.

If you know the resizes that you will need ahead of time use php to resize them for you as its nice and easy to just prepend something like sm_ to the beginning of the master images filename for a resized image. This means you only need to store the master image filename and as long as you stick to a convention you can easily reference all your resizes from that.

If you don't know what sizes are going to be needed, its best to do it when an image is requested although that is a little trickier.
 
Back
Top Bottom