SitePoint Sponsor |
|
User Tag List
Results 1 to 12 of 12
-
May 9, 2009, 18:44 #1
- Join Date
- Mar 2003
- Location
- Western, PA - USA
- Posts
- 94
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Please recommend a simple and basic image gallery tool...
...I have a client that runs a small and simple shopping cart site. He sells parts and also does some custom work. Up to this point has has had about a dozen images of custom work examples that I have in a static html page for him.
Now he wants to expand that gallery about once a day or so with more pics. I'm familiar with bigger image galleries that allow all kinds of Categories, Albums, etc. He doesn't want that. It will be one album only so everything i've found so far is basically too much. But all the simple ones I can find don't offer 'online wysiwyg' type of image upload and management.
So I am either looking for a simple gallery tool, or a decent tutorial on where to write on in PHP.
Anyone help guide me in the right direction please?
-
May 9, 2009, 23:56 #2
Its not so difficult. Your top option is to restrict the type of files he can upload to jpg or jpeg if he is microsoft
The bad news is that the web is garbage when it comes to tutorials on this subject as I found out when I did mine.
If you PM me with an email addy I can send you some working code that will get you started. There may be some on
webmaster resourcesLast edited by Mattinblack; May 16, 2009 at 04:55.
-
May 10, 2009, 00:48 #3
- Join Date
- Dec 2005
- Location
- Cambridge, England
- Posts
- 2,443
- Mentioned
- 82 Post(s)
- Tagged
- 3 Thread(s)
I would go for saving the photos in a folder and then reading the folder contents; you could always move to a database if you want later.
I have some gallery code on my site you can look at it although it uses Imagemagick for the resizing.
http://www.rubblewebs.co.uk/code.php
In the past I have added a text file on upload so that you can add some text that is linked to the image through the filename. I do that on this site http://www.rubble.info/gallery.php
I think writting your own or modifying some code is a lot better than using a ready written one as you have more control.
If you want some ideas and help I can help you out.
-
May 10, 2009, 17:11 #4
- Join Date
- Mar 2003
- Location
- Western, PA - USA
- Posts
- 94
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Matt,
Your code is very helpful... however it does not exactly suit what I need in this situation.
So to clarify - I have a single admin user that needs to be able to manipulate his small "Custom Work" gallery without ftp/coding the page. So I am trying to find a simple and stripped down gallery type script and/or code so that he can manage his gallery with wysiwyg type controls.
I do NOT need something that visitors will do anything to except view like a static gallery.
I still need help, nothing I have found so far is working out.
-
May 10, 2009, 19:08 #5
-
May 11, 2009, 00:08 #6
- Join Date
- Dec 2005
- Location
- Cambridge, England
- Posts
- 2,443
- Mentioned
- 82 Post(s)
- Tagged
- 3 Thread(s)
The problem with gallery 2 and some of the other gallerys is they are so large with user comments etc. Most of which people do not use.
I will try to modify one of my codes later and see if its suitable.
-
May 11, 2009, 00:46 #7
- Join Date
- Dec 2005
- Location
- Cambridge, England
- Posts
- 2,443
- Mentioned
- 82 Post(s)
- Tagged
- 3 Thread(s)
I am on holiday this week but am supposed to be doing some DIY so this is just a quick reply
PHP Code:<?php
// Open the directory and create an array of the images
// Directory to read images from
$dir = 'gallery/Other_pics/';
foreach (glob($dir."{*.jpg}", GLOB_BRACE) as $filename)
{
// Remove the .jpg extension from the image name for use in the image alt.
$image = explode('/', $filename);
$altTag = substr($image[2], 0, -4);
// Display the images 200px heigh ( need to alter 2 lines if changing the 200 value )
$size = getimagesize($filename);
$width = round($size[0]*(200/$size[1]));
$constrain = "width=\"$width\" height=\"200\"";
// Get the text file information
$text = str_replace('.jpg', '.txt', $filename);
$fh = fopen( $text, 'r' );
$blurb = fread( $fh, 500 );
fclose( $fh );
// Display the photo and information
echo "<img border=\"0\" src=\"".$filename."\" alt=\"".str_replace('_', ' ', $altTag)."\" ".$constrain." /></a><br>".$blurb."<br>\n";
}
?>
As I say just a quick reply; you would need to add some styling etc.
-
May 11, 2009, 05:40 #8
Ok here is a proposal. I dont think precisely what you want is available for free so for $20 I will produce a custom script that will allow the admin to log in, upload files and then organise them into pages with a title (and comments if needed. He can control the titles of each page and every gallery page will link to every other automagically using titles as link text. He can also control the picture sizes, display ord (that determines position on page) and the navigation link back to the main site. The page will be templated (via html) so the look of them is entirely cutomisable by you.
The admin controls will appear in a seperate div tacked on to the bottom of the page he is editing so it will be very precisely WYSIWYG.
-
May 11, 2009, 09:34 #9
- Join Date
- Dec 2005
- Location
- Cambridge, England
- Posts
- 2,443
- Mentioned
- 82 Post(s)
- Tagged
- 3 Thread(s)
Here is some upload code you can use; its not safe for general use and could do with some work but it will upoad an image, create 2 versions ( using GD ) and save a text file.
The code I provided this morning should be able to read the information and create the page.
You would need to modify it to what you want exactly.
PHP Code:<?php
// If the form is submitted do this else display the form
if ( isset( $_POST[submit] ) ) {
// Put the text into a variable
$text = $_POST[text];
// Where to save the images
$dir = "photos/";
// Maximium image size thumb
$max_width = "200";
$max_height = "200";
// Maximium image size normal
$max_width1 = "400";
$max_height1 = "400";
// Get the filename
$up_file = $_FILES['filename'];
// Read the details of the file
$filetype = $up_file['type'];
$filename = $up_file['name'];
$tempname = $up_file['tmp_name'];
// Names to use for the thumbnail
$new_name = $dir."th_".$filename;
// Names to use for the normal
$new_name1 = $dir.$filename;
// Get the uploaded image sizes
$size = GetImageSize( $tempname );
$width_ratio = ( $size[0] / $max_width );
$height_ratio = ( $size[1] / $max_height );
$width_ratio1 = ( $size[0] / $max_width1 );
$height_ratio1 = ( $size[1] / $max_height1 );
// Resize by the longest side and keep the aspect ratio
// Thumbnail
if( $width_ratio >= $height_ratio ) {
$ratio = $width_ratio; }
else {
$ratio = $height_ratio; }
$new_width = round( $size[0] / $ratio );
$new_height = round( $size[1] / $ratio );
// Normal
if( $width_ratio1 >= $height_ratio1 ) {
$ratio1 = $width_ratio1; }
else {
$ratio1 = $height_ratio1; }
$new_width1 = round( $size[0] / $ratio1 );
$new_height1 = round( $size[1] / $ratio1 );
// The image to use to create the thumbnail version etc.
$src_img = ImageCreateFromJPEG( $tempname );
// Create thumbnail
$thumbnail = ImageCreateTrueColor( $new_width, $new_height );
ImageCopyResampled( $thumbnail, $src_img, 0, 0, 0, 0,( $new_width-1 ),( $new_height-1 ),$size[0],$size[1] );
ImageJPEG( $thumbnail, $new_name );
ImageDestroy( $thumbnail );
// Create normal sized
$normal = ImageCreateTrueColor( $new_width1, $new_height1 );
ImageCopyResampled( $normal, $src_img, 0, 0, 0, 0,( $new_width1-1 ),( $new_height1-1 ),$size[0],$size[1] );
imagejpeg( $normal, $new_name1 );
ImageDestroy( $normal );
// create a new file for the text to go with the image
$text_file = str_replace ( "jpg", "txt", $new_name1 );
$fp = fopen("$text_file", "w");
fwrite($fp, "$text");
fclose($fp);
}
else {
?>
<form enctype='multipart/form-data' name='upload' method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'>
File: <input name='filename' type='file' /><br>
Text: <input name='text' type='text' size='100'/>
<br /><input name='submit' type='submit' id='submit' value='Submit' />
</form>
<?php } ?>Last edited by Rubble; May 11, 2009 at 09:35. Reason: Added note
-
May 14, 2009, 05:35 #10
- Join Date
- Mar 2003
- Location
- Western, PA - USA
- Posts
- 94
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you very much! I am working on this today finally, and have gotten as far as the upload page. I added it to my existing admin section and received the following errors which I believe all stem from lack of fopen() capability. Some input please?
- Warning: imagejpeg(): Unable to open 'http://www.*.com/images/th_pack.jpg' for writing: No such file or directory in /hsphere/local/home/*/*.com/admin/include/a_main.php on line 76
- Warning: imagejpeg(): Unable to open 'http://www.*.com/images/pack.jpg' for writing: No such file or directory in /hsphere/local/home/*/*.com/admin/include/a_main.php on line 82
- Warning: fopen(): URL file-access is disabled in the server configuration in /hsphere/local/home/*/*.com/admin/include/a_main.php on line 87
- Warning: fopen(http://www.*.com/images/pack.txt): failed to open stream: no suitable wrapper could be found in /hsphere/local/home/*/*.com/admin/include/a_main.php on line 87
- Warning: fwrite(): supplied argument is not a valid stream resource in /hsphere/local/home/*/*.com/admin/include/a_main.php on line 88
- Warning: fclose(): supplied argument is not a valid stream resource in /hsphere/local/home/*/*.com/admin/include/a_main.php on line 89
PHP Code:<p align="center">Admin Main Page</p>
<p align="center">---------------</p>
<p align="center">Bob, I fixed everything that I could find. I also have the new design on the main page. I fixed up the checkout process
so that it looks decent and functions much better. The only input from AO I got is that we're missing the color selection
part for some items. I don't think that is a real big deal for your purposes, but let me know if you want me to work on it.</p>
<!--<p align="center">Choose a menu from the left navigation to get started</p>-->
<?php
// $_SESSION['login_return_url'] = $_SERVER['REQUEST_URI'];
// checkUser();
// If the form is submitted do this else display the form
if ( isset( $_POST[submit] ) ) {
// Put the text into a variable
$text = $_POST[text];
// Where to save the images
$dir = "http://www.*.com/images/tuna/";
// Maximium image size thumb
$max_width = "200";
$max_height = "150";
// Maximium image size normal
$max_width1 = "800";
$max_height1 = "600";
// Get the filename
$up_file = $_FILES['filename'];
// Read the details of the file
$filetype = $up_file['type'];
$filename = $up_file['name'];
$tempname = $up_file['tmp_name'];
// Names to use for the thumbnail
$new_name = $dir."th_".$filename;
// Names to use for the normal
$new_name1 = $dir.$filename;
// Get the uploaded image sizes
$size = GetImageSize( $tempname );
$width_ratio = ( $size[0] / $max_width );
$height_ratio = ( $size[1] / $max_height );
$width_ratio1 = ( $size[0] / $max_width1 );
$height_ratio1 = ( $size[1] / $max_height1 );
// Resize by the longest side and keep the aspect ratio
// Thumbnail
if( $width_ratio >= $height_ratio ) {
$ratio = $width_ratio; }
else {
$ratio = $height_ratio; }
$new_width = round( $size[0] / $ratio );
$new_height = round( $size[1] / $ratio );
// Normal
if( $width_ratio1 >= $height_ratio1 ) {
$ratio1 = $width_ratio1; }
else {
$ratio1 = $height_ratio1; }
$new_width1 = round( $size[0] / $ratio1 );
$new_height1 = round( $size[1] / $ratio1 );
// The image to use to create the thumbnail version etc.
$src_img = ImageCreateFromJPEG( $tempname );
// Create thumbnail
$thumbnail = ImageCreateTrueColor( $new_width, $new_height );
ImageCopyResampled( $thumbnail, $src_img, 0, 0, 0, 0,( $new_width-1 ),( $new_height-1 ),$size[0],$size[1] );
ImageJPEG( $thumbnail, $new_name );
ImageDestroy( $thumbnail );
// Create normal sized
$normal = ImageCreateTrueColor( $new_width1, $new_height1 );
ImageCopyResampled( $normal, $src_img, 0, 0, 0, 0,( $new_width1-1 ),( $new_height1-1 ),$size[0],$size[1] );
imagejpeg( $normal, $new_name1 );
ImageDestroy( $normal );
// create a new file for the text to go with the image
$text_file = str_replace ( "jpg", "txt", $new_name1 );
$fp = fopen("$text_file", "w");
fwrite($fp, "$text");
fclose($fp);
}
else {
?>
<form enctype='multipart/form-data' name='upload' method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'>
File: <input name='filename' type='file' /><br>
Text: <input name='text' type='text' size='100'/>
<br /><input name='submit' type='submit' id='submit' value='Submit' />
</form>
<?php
}
?>
-
May 14, 2009, 06:46 #11
change the upload path to system path:
PHP Code:<p align="center">Admin Main Page</p>
<p align="center">---------------</p>
<p align="center">Bob, I fixed everything that I could find. I also have the new design on the main page. I fixed up the checkout process
so that it looks decent and functions much better. The only input from AO I got is that we're missing the color selection
part for some items. I don't think that is a real big deal for your purposes, but let me know if you want me to work on it.</p>
<!--<p align="center">Choose a menu from the left navigation to get started</p>-->
<?php
// $_SESSION['login_return_url'] = $_SERVER['REQUEST_URI'];
// checkUser();
// If the form is submitted do this else display the form
if (isset($_POST['submit']))
{
// Put the text into a variable
$text = $_POST['text'];
// Where to save the images
$dir = "/hsphere/local/home/images/tuna/";
// Maximium image size thumb
$max_width = "200";
$max_height = "150";
// Maximium image size normal
$max_width1 = "800";
$max_height1 = "600";
// Get the filename
$up_file = $_FILES['filename'];
// Read the details of the file
$filetype = $up_file['type'];
$filename = $up_file['name'];
$tempname = $up_file['tmp_name'];
// Names to use for the thumbnail
$new_name = $dir . "th_" . $filename;
// Names to use for the normal
$new_name1 = $dir . $filename;
// Get the uploaded image sizes
$size = GetImageSize($tempname);
$width_ratio = ($size[0] / $max_width);
$height_ratio = ($size[1] / $max_height);
$width_ratio1 = ($size[0] / $max_width1);
$height_ratio1 = ($size[1] / $max_height1);
// Resize by the longest side and keep the aspect ratio
// Thumbnail
if ($width_ratio >= $height_ratio)
{
$ratio = $width_ratio;
}
else
{
$ratio = $height_ratio;
}
$new_width = round($size[0] / $ratio);
$new_height = round($size[1] / $ratio);
// Normal
if ($width_ratio1 >= $height_ratio1)
{
$ratio1 = $width_ratio1;
}
else
{
$ratio1 = $height_ratio1;
}
$new_width1 = round($size[0] / $ratio1);
$new_height1 = round($size[1] / $ratio1);
// The image to use to create the thumbnail version etc.
$src_img = ImageCreateFromJPEG($tempname);
// Create thumbnail
$thumbnail = ImageCreateTrueColor($new_width, $new_height);
ImageCopyResampled($thumbnail, $src_img, 0, 0, 0, 0, ($new_width - 1), ($new_height -
1), $size[0], $size[1]);
ImageJPEG($thumbnail, $new_name);
ImageDestroy($thumbnail);
// Create normal sized
$normal = ImageCreateTrueColor($new_width1, $new_height1);
ImageCopyResampled($normal, $src_img, 0, 0, 0, 0, ($new_width1 - 1), ($new_height1 -
1), $size[0], $size[1]);
imagejpeg($normal, $new_name1);
ImageDestroy($normal);
// create a new file for the text to go with the image
$text_file = str_replace("jpg", "txt", $new_name1);
$fp = fopen("$text_file", "w");
fwrite($fp, "$text");
fclose($fp);
}
else
{
?>
<form enctype='multipart/form-data' name='upload' method='post' action='<?php echo
$_SERVER['PHP_SELF']; ?>'>
File: <input name='filename' type='file' /><br>
Text: <input name='text' type='text' size='100'/>
<br /><input name='submit' type='submit' id='submit' value='Submit' />
</form>
<?php
}
?>my mobile portal
ghiris.ro
-
May 14, 2009, 08:27 #12
- Join Date
- Dec 2005
- Location
- Cambridge, England
- Posts
- 2,443
- Mentioned
- 82 Post(s)
- Tagged
- 3 Thread(s)
Thats a pain
The fopen you could try setting in your .htaccess file; search Google for some examples but I assume that it still won't work.
How computer savy is your user ? You could get them to write a file and use one of the "Send to FTP" programs where you setup the info and then when they right click on the file it is uploaded. One small problem with this is that they need to get the name of the file correct.
This is a program I tried a few years that worked OK but it looks like the developers website is closed.
http://www.snapfiles.com/get/sendtoftp.html
Another way would be to use a database. I have not used sqllite which may be all you need rather than Mysql. Do you have a Mysql database ?
The final straw is change your hosts
With the images have you CHMOD the images folder to 777 or 755?
I would also echo the paths to see you are getting what you expect:
PHP Code:// Names to use for the thumbnail
$new_name = $dir."th_".$filename;
echo $new_name;
echo "<br>";
// Names to use for the normal
$new_name1 = $dir.$filename;
echo $new_name1;
echo "<br>";
Last edited by Rubble; May 14, 2009 at 08:30. Reason: Added note
Bookmarks