This is a dedicated thread for discussing the SitePoint article 'Build An Automated PHP Gallery System In Minutes'
| SitePoint Sponsor |
This is a dedicated thread for discussing the SitePoint article 'Build An Automated PHP Gallery System In Minutes'
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
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
-Sam
Sam Hastings
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
Thanks
firstly, thanks for comments to all ...
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.1) There is a small bug in upload.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 ...Reason is some missing lines in viewgallery.php
Originally Posted by article
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
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:
PHP Code:// 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 ...![]()
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![]()
![]()
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/showt...hreadid=122217
PHP Link Directory Script -easy to create and profitable too
What Google "thinks"
Does Google Trust You?
What it means to be human




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.





the patent has expired and I seem to recall that gif support is being reintroduced into the bundled GD library , perhaps as early as 4.3.3 ?Originally Posted by mayank


That would be great ...





Nope GD could legally support GIF at the moment as the patent has expired although as stated on the GD website earlier this year there is to be no GIF support until early 2004 for some reason or other that I cannot remember...
Though I think they're waiting on something or other before they release the GIF support in the current GD releases... ?





What kind of issues ?




I'm getting this error on line 34 of upload.phpthis is line 34Fatal error: Maximum execution time of 60 seconds exceeded in /home/nathanr/public_html/radiorallyv2/pic/upload.php on line 34and this is the block of code around line 34PHP Code:while($counter <= count($photos_uploaded)) {
this is my whole scriptPHP Code:while($counter <= count($photos_uploaded)) {
if($photos_uploaded['size'][$counter] > 0) {
if(!array_key_exists($photos_uploaded['type'][$counter], $photo_types)) {
$result_final .= 'File ' . ($counter + 1) . ' is not a photo<br />';
} else {
// Great the file is an image, we will add this file
}
}
}
PHP Code:<? include_once("../header.php" ); ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><img src="../img/banner2.jpg" border="0" vspace="0" hspace="0" name="banner"></td>
</tr>
<tr>
<td valign=top width=16% class="menu">
<? include_once("../menu2.php" ); ?>
</td>
<td width="*%" valign=top>
<?
// include the database specific information
include_once("../inc/db.php" );
// make a connection to the rrc database
dbConnect();
$images_dir = 'photos';
// Fetch the image array sent by preuploaed.php
$photos_uploaded = $_FILES['photo_filename'];
// Fetch the image caption array
$photo_captions = $_POST['photo_captions'];
$photo_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'image/x-png' => 'png'
);
while($counter <= count($photos_uploaded) ) {
if($photos_uploaded['size'][$counter] > 0) {
if(!array_key_exists($photos_uploaded['type'][$counter], $photo_types)) {
$result_final .= 'File ' . ($counter + 1) . ' is not a photo<br />';
} else {
// Great the file is an image, we will add this file
}
}
}
$query = "INSERT INTO gallery_photos (photo_filename, photo_caption, photo_category) VALUES ('0','" . $photo_captions[$counter] . "','" . $_POST['category'] . "')";
mysql_query($query);
$new_id = mysql_insert_id(); // New Id generated
// Get the filetype of the uploaded file
$filetype = $photos_uploaded['type'][$counter];
// Get the extension for the new name
$extension = $known_photo_types[$filetype];
// Generate a new name
$filename = "$new_id.$extension";
// let's update the filename now
$query = "UPDATE gallery_photos SET photo_filename = '$filename' WHERE photo_id = '$new_id'";
mysql_query($query);
copy($photos_uploaded['tmp_name'][$counter], $images_dir . '/' . $filename);
$size = GetImageSize($images_dir . "/" . $filename);
// 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]);
}
}
$gd_function_suffix = array (
'image/pjpeg' => 'JPEG',
'image/jpeg' => 'JPEG',
'image/gif' => 'GIF',
'image/bmp' => 'WBMP',
'image/x-png' => 'PNG'
);
$function_suffix = $gd_function_suffix[$filetype];
$function_to_read = 'ImageCreateFrom' . $function_suffix;
$function_to_write = 'Image' . $function_suffix;
// Read the source file
$source_handle = $function_to_read($images_dir . '/' . $filename );
if ($source_handle) {
// Let's create a blank image for the thumbnail
$destination_handle = ImageCreate($thumbnail_width, $thumbnail_height);
// Now we resize it
ImageCopyResized($destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]);
}
// Lets save the thumbnail
$function_to_write($destination_handle, $images_dir . '/tb_' . $filename);
ImageDestroy($destination_handle);
?>
</td>
</tr>
</table>
<? include_once("../footer.php" ); ?>
The while loop will never end as the counter is not being incremented. It looks like the code is not correctly formulated. You might want to download the archive with the article, from here
also, if you are uploading many images at once, you would like to reset the default execution time limit of 30 seconds,
PHP Code:set_time_limit(0);
Bookmarks