I got the class above to function, only I now have to dynamicaly create thumbnails prior to downloading the images to save bandwith.
I have added the following methods to my class to allow it to create thumnails, only its not working right.
For some reason it a: only creates 1 thumbnail that b: it places in the www root and c: is named tn_ with no extention.
Please could someone take a quick look and let me know how to fix it.
here are the methods:
Code: Select all
function makethumbs(){
$imagefolder=$this->location ."/". $this->galleryName;
$thumbsdir=$this->location .$this->thumbsFolder.$this->galleryName;
$fileList = $this->getFileList();
if ($fileList[0]=""){
echo "no files in directory";
}else{
for ($c=0; $c<=sizeof($fileList);$c++){
$name =$fileList[$c];
if (!preg_match("/^tn_/",$name)){
$pics[$c]= $name;
}
}
}
if ($pics[0]=""){
echo "no files in directory";
}else{
for ($c=0; $c<=sizeof($pics);$c++){
echo "<br>ok<br>";
$this->createthumb($pics[$c],"tn_".$pics[$c],150,150);
}
}
}
function createthumb($name,$filename,$new_w,$new_h)
{
$filenameE=explode(".",$name);
if (preg_match("/jpg|jpeg/",$filenameE[1])){$src_img=imagecreatefromjpeg($name);}
if (preg_match("/png/",$filenameE[1])){$src_img=imagecreatefrompng($name);}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y)
{
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y)
{
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y)
{
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$filenameE[1]))
{
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}If it would help I can post a link to a zip of the full working class