Resizes jp(e)g files within the $src-directory and stores * the thumbnails in the $path-directory by adding a "_" to the filename. */ function resize() { $count = 0; $d = dir($this->src ); $fp = fopen("$this->path/$this->idxfile", "a+" ); while($entry=$d->read() ) { if(preg_match("/.+\.jp[e]{0,1}g$/i", $entry )) { if(!file_exists("$this->path/_$this->prefix$entry" )) { $src = ImageCreateFromJPEG("$d->path/$entry" ); $org_h = imagesy($src ); $org_w = imagesx($src ); // get size of template image $tpl_size = GetImageSize("$this->tpl" ); print_r($tpl_size ); if($org_h > $org_w ) { // height is bigger than width $cfg[height] = $tpl_size[1]; $cfg[width] = floor($cfg[height] * $org_w / $org_h ); $cfg[dstX] = ($tpl_size[0] - $cfg[width]) / 2; $cfg[dstY] = 0; } else { // width is bigger than height $cfg[width] = $tpl_size[0]; $cfg[height] = floor($cfg[width] * $org_h / $org_w ); $cfg[dstX] = 0; $cfg[dstY] = ($tpl_size[1] - $cfg[height]) / 2; } $img = ImageCreateFromPNG("$this->tpl" ); ImageCopyResized($img, $src, $cfg[dstX], $cfg[dstY], 0, 0, $cfg[width], $cfg[height], $org_w, $org_h ); ImageJPEG($img, "$this->path/_$this->prefix$entry", 90 ); ImageDestroy($img ); // create an index file with "thumbnailfile, filename, width, height" if(!strstr(join("", file("$this->path/$this->idxfile") ), $entry )) { fwrite($fp, "_$this->prefix$entry,$entry,$org_w,$org_h"."\n", strlen("_$this->prefix$entry,$entry,$org_w,$org_h"."\n" )); } } } } fclose($fp); $d->close(); } /** * clean-up cache images where there is no original image and update indexlist */ function checkup() { // get the current indexfile $idx = file("$this->path/$this->idxfile" ); $i=0; // make a reference string $d = dir($this->src ); while($entry=$d->read() ) { $ref_idx .= "$entry,"; } $d->close(); // crosscheck for obsolete thumbnails for($f=0; $fpath/".$items[0])) unlink("$this->path/".$items[0] ); } } // update indexfile $fp = fopen("$this->path/$this->idxfile", "w+" ); for($k=0; $kpath/$this->idxfile"); // calculate start and end of page index $cfg[start] = $HTTP_GET_VARS[$this->page] * $cols * $rows; $cfg[stop] = ($HTTP_GET_VARS[$this->page] + 1 ) * $cols * $rows; $table .= "\n\n"; $table .= "\n\n"; # $table .= "\n\n"; // construct table for($j=$cfg[start]; $j<$cfg[stop]; $j++ ) { $itemlist = explode(",", $idx[$j] ); if(preg_match("/.+\.jp[e]{0,1}g$/i", $itemlist[1] )) { $table .= sprintf("\n", "$this->src/".$itemlist[1], $itemlist[2]+20, $itemlist[3]+20, "$this->path/".$itemlist[0] ); $k++; if($k == $cols ) { $table .= "\n\n"; $k = 0; } } } $table .= "\n\n
" . $this->select_gallery($multiple ) . "
\"Click\"
"; // create page index $table .= "$this->desc"; for($n=0, $l=0; $size=count($idx), $n<$size; $n=$n+($cols*$rows) ) { if($GLOBALS[$this->page] == $l) { $table .= sprintf("%s\n", ""); } else { $table .= sprintf("%s\n", $this->url($this->page, "$this->page=$l" ), ++$l ); } } $table .= "
\n"; $table .= "\n"; return $table; } /** * Proper handling of query-string to make this script * application-independent and easy-integratable. * * @param $index, $addon */ function url($index="page", $addon="" ) { global $HTTP_GET_VARS, $QUERY_STRING; // a dirty hack for those who use arrays in the query string foreach($HTTP_GET_VARS as $key => $val ) { if(is_array($val) == "array") { $tmp .= "&" . $key . "[" . key($val) . "]=" . current($val); } else { $q[$key] = $val; } } if(is_array($q )) { // remove $index element from the list unset($q[$index]); // create new query-string foreach($q as $key => $val ) { $str .= "$key=$val&"; } return $str . $addon . $tmp; } else { return $addon . $tmp; } } } ?>