Create thumbnails using PHP or add thumbnails manully?

I have a folder called "Gallery" inside which I created a folder for Thumbails called "Gallery-Thumbs", where I manually add thumbnails.

My question is: is it better to manually add thumbnails or create thumbnails dynamically using "GD" or "ImageMagick".

Problems adding thumbnails manually

  • If I forget to add a thumbnail for the photo, the gallery chain is broken.
  • You need to resize all images to create thumbnails.

So does the PHP ImageProcessing function use the extra overhead when sketching or the right approach?

- Updated to respond to requests

  • How do you add images to the gallery folder?

    • Direct file download
  • Access to these images and thumbnails?

    • I use glob to get a list of files in the corresponding folders
  • How do you (want) to compare images with thumbnails?

    • For thumbnails I use imageName-thumb.jpg, so they appear in the list in the same order as in the folder with the main image.
+3
source share
5 answers

Use PHP to create thumbnails once and save them in the thumbnail directory with the same file names. Then use these thumbnails, which are now ready for use.

+2
source

If you go to some dynamic image processing tool, it will be a little time-consuming process, except that it will be a great technique.

, :

  • script
  • .
+1

th_ . , , , . , . , ; . Bother , .. Imagemagick. http://www.rubble.info/gallery/

, , .

, php Imagemagick.

0

GD - , , . . URL- GET.

Smart Image Resizer ShiftingPixel: http://shiftingpixel.com/2008/03/03/smart-image-resizer/

, , -, , : http://www.eastwood-whelpton.co.uk/about/gallery.php

- GD Smart Image Resizer.

I can also provide the PHP code that I used if you want to use examples. This specific code automatically adds any images found in my gallery folder to this page.

0
source

As already mentioned, you need PHP 5 with GD support. If you have this, then here is a very convenient function for creating thumbnails of specified sizes and quality ( $options) from each image in a given directory ( $from_dir) and saving them to another directory ( $to_dir).

function make_thumbnails($from_dir,$to_dir, $options){
    $files = scandir($from_dir);
    $exclude = array('.','..','etc.');
    foreach($files as $fi => $fv){
        if(!in_array($fv,$exclude)){
            $from_file = $from_dir.$fv;
            $to_file = $target_dir.$fv;
            list($img_width, $img_height,$img_type) = getimagesize($from_file);
            $scale = min($options['max_width'] / $img_width,
                                        $options['max_height'] / $img_height
                               );
            $new_width = $img_width * $scale;
            $new_height = $img_height * $scale;
            $new_img = imagecreatetruecolor($new_width, $new_height);
            $src_img = imagecreatefromjpeg($from_file);
            $success = $src_img && imagecopyresampled(
                    $new_img,
                    $src_img,
                    0, 0, 0, 0,
                    $new_width,
                    $new_height,
                    $img_width,
                    $img_height
            ) && imagejpeg($new_img, $to_file, $options['quality']);
                              //Monitor results with $success - returns 1 or null
            echo '<br />success:['.$success.']';
        }
    }
}

//Set options
$from_dir = ':/source/dir';
$to_dir = ':/destination/dir';
$options = array();
$options['max_width'] = 100;
$options['max_height'] = 100;
$options['quality'] = 100;

// Make thumbs...
make_thumbnails($from_dir,$to_dir,$options);
0
source

All Articles