Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Page Slug
#3
Yhea, I've tried that, it only breaks the site.
Maybe got something to do with other parts of the script.

Code:
<?php
function make_thumb($src,$dest,$desired_width) {
    $source_image = imagecreatefromjpeg($src);
    $width = imagesx($source_image);
    $height = imagesy($source_image);
    $desired_height = floor($height*($desired_width/$width));
    $virtual_image = imagecreatetruecolor($desired_width,$desired_height);
    imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);
    imagejpeg($virtual_image,$dest);
}

function get_files($images_dir,$exts = array('jpg')) {
    $files = array();
    if($handle = opendir($images_dir)) {
        while(false !== ($file = readdir($handle))) {
            $extension = strtolower(get_file_extension($file));
            if($extension && in_array($extension,$exts)) {
                $files[] = $file;
            }
        }
        closedir($handle);
    }
    return $files;
}

function get_file_extension($file_name) {
    return substr(strrchr($file_name,'.'),1);
}

$images_dir = 'data/uploads/images/PAGE SLUG HERE/';
$thumbs_dir = 'data/uploads/images/PAGE SLUG HERE/thumbnails/';
$thumbs_width = 200;
$images_per_row = 4;

$image_files = get_files($images_dir);
if(count($image_files)) {
    $index = 0;
    foreach($image_files as $index=>$file) {
        $index++;
        $thumbnail_image = $thumbs_dir.$file;
        if(!file_exists($thumbnail_image)) {
            $extension = get_file_extension($thumbnail_image);
            if($extension) {
                make_thumb($images_dir.$file,$thumbnail_image,$thumbs_width);
            }
        }
        echo '<a href="',$SITEURL.$images_dir.$file,'" class="group" rel="gallery"><img src="',$SITEURL.$thumbnail_image,'" /></a>';
        if($index % $images_per_row == 0) { echo '<div class="clear"></div>'; }
    }
    echo '<div class="clear"></div>';
}
else {
    echo '<p>There are no images in this gallery.</p>';
}

?>
Reply


Messages In This Thread
Get Page Slug - by Staurvik - 2011-04-01, 01:34:18
Get Page Slug - by n00dles101 - 2011-04-01, 01:42:31
Get Page Slug - by Staurvik - 2011-04-01, 01:47:04
Get Page Slug - by n00dles101 - 2011-04-01, 01:52:17
Get Page Slug - by Staurvik - 2011-04-01, 01:55:49



Users browsing this thread: 1 Guest(s)