Build An Automated PHP Gallery System In Minutes

This is a dedicated thread for discussing the SitePoint article ‘Build An Automated PHP Gallery System In Minutes

Turning off error reporting does NOT fix problems, much better to fix the code so it doesn’t error instead if you can.
And IMHO heredoc syntax is normal.

Adding this error_reporting(0); to the top of config.inc.php makes it work like it’s supposed to…

Why the Heredoc syntax? why not just code it normally.

Good article, but the link for the ZIP ‘in the downloadable archive’ is 404

Not a bad article to introduce us all to the wonderful world of uploading our dirty negs to the Net :lol:

Seriously though for beginners or for those looking to getting started with PHP this would be a great project to build up from …

very nicely structured tutorial …

This is something I’ve been meaning to do for a while. No doubt I’ll be using this tutorial when I do!

Thanks :slight_smile:

-Sam

Some minor points:

  1. There is a small bug in upload.php:

    if($size[0] > $size[1])
    {
    $thumbnail_width = 100;
    $thumbnail_height = (int)(100 * $size[0] / $size[1]);
    }
    else
    {
    $thumbnail_width = (int)(100 * $size[0] / $size[1]);
    $thumbnail_height = 100;
    }

    should be:

    if($size[0] > $size[1])
    {
    $thumbnail_width = 100;
    $thumbnail_height = (int)(100 * $size[1] / $size[0]);
    }
    else
    {
    $thumbnail_width = (int)(100 * $size[0] / $size[1]);
    $thumbnail_height = 100;
    }

  2. Adding your own design in design.inc.php doesn’t work. Reason is some missing lines in viewgallery.php:

    $result_final

    should be:

    $design_header
    $result_final
    $design_footer

    Apart from this it is a nice article and indeed a timesaver :wink:
    Thanks

firstly, thanks for comments to all …

  1. There is a small bug in upload.php:

it looks ok … if you notice in both cases i am taking one dimension as constant and calculating the other on basis of its aspect ratio … so in the case where the image is wide, i am taking the width as constant, e.g. 100 and calculating its height; vice-versa for the tall image.

Reason is some missing lines in viewgallery.php

well i didn’t write the code for design inclusion in viewgallery.php for that matter in any of the scripts; becuase i didn’t wanted the code to look complex. In the paragraph for the desgin section i have mentioned that it will be required to add the $design_header & $design_footer before output, in this case $result_final …

I missed the paragraph for the design section, my fault.

I am sorry but I don’t agree with your remark about creating the thumbnails. In my view the code is not correct here.
Take a picture with size 640x480.
Original code:
Landscape: size[0] = 640, size[1] = 480, thumbnail_width = 100, thumbnail_height = 133 (wrong aspect ratio, image looking weird)
Portrait: size[0] = 480, size[1] = 600, thumbnail_width = 75, thumbnail_height = 100 (correct aspect ratio

With the corrected code the thumbnails are 100x75 or 75x100 which is as expected.

i’ve been working a gallery for like a week without a tutorial…just asking questions around. i think ill take a look at this…

i take my words back, you are right. I was looking at the code i had and not the one i wrote in the article (a typo). Somehow i missed your point … thanks for correcting :agree:

btw, i was considering to add some code to the article,

Scenario: If you want to limit the size of your thumbnail to its width x height … e.g. you don’t a thumbnail for a wide image to be bigger than 100x75 and thumbnail for a tall image to be bigger than 75x100

then the following code could be used:


		// Settings
		$Config_tbwidth_wide = 100; // width of wide image
		$Config_tbheight_wide = 75; // height of wide image

		$Config_tbwidth_tall = 75; // width of tall image
		$Config_tbheight_tall = 100; // height of tall image


		// The code
		if($size[0] > $size[1])
		{
			$thumbnail_width = $Config_tbwidth_wide;
			$thumbnail_height = (int)($Config_tbwidth_wide * $size[1] / $size[0]);

			if($thumbnail_height > $Config_tbheight_wide)
			{
				$thumbnail_height = $Config_tbheight_wide;
				$thumbnail_width = (int)($Config_tbheight_wide * $size[0] / $size[1]);
			}
		}
		else
		{
			$thumbnail_width = (int)($Config_tbheight_tall * $size[0] / $size[1]);
			$thumbnail_height = $Config_tbheight_tall;

			if($thumbnail_width > $Config_tbwidth_tall)
			{
				$thumbnail_width = $Config_tbwidth_tall;
				$thumbnail_height = (int)($Config_tbwidth_tall * $size[1] / $size[0]);
			}
		}

thought it might be useful … :cool:

hey cool something i wanted …

cool! i like it …

Great article! How about a sequel …

Just look to see if there isn’t another typo in there though :lol: :smiley:

:slight_smile: sure i will look out those errors this time …

What about the problem with GIF images brought up in this thread?
http://www.sitepointforums.com/showthread.php?threadid=122217

You cannot use GIF images with the GD library anymore, due to copyright issues.

yes the official versions of GD won’t support GIF … though there are some modified (older) versions of GD which do support GIF but as Travis said they are in violation of the copyright.