diff --git a/index_template.htm b/index_template.htm deleted file mode 100644 index e69de29..0000000 diff --git a/page_template.htm b/page_template.htm deleted file mode 100644 index 6d92929..0000000 --- a/page_template.htm +++ /dev/null @@ -1,20 +0,0 @@ - - -
- -##DESCRIPTION##
- - ##IMAGESECTION## - - ##ENDIMAGESECTION## - - ##DOWNLOADSECTION## - ##FILENAME## - ##ENDDOWNLOADSECTION## - - diff --git a/rebuild.php b/rebuild.php index b10aa85..dc43caf 100644 --- a/rebuild.php +++ b/rebuild.php @@ -4,13 +4,18 @@ // ```````````````````` define('BASEDIR', __DIR__.'\\'); +define('SITE_TITLE', 'code.ivysaur.me'); +define('PAGE_THUMB_W', 60); +define('PAGE_THUMB_H', 60); // clean up wwwroot if (file_exists(BASEDIR.'wwwroot')) { rename(BASEDIR.'wwwroot', BASEDIR.'wwwroot.old.'.uniqid()); } + mkdir(BASEDIR.'wwwroot'); +mkdir(BASEDIR.'wwwroot/srv'); // List of projects @@ -26,11 +31,46 @@ foreach($ls as $dirname) { } } +/** + * Create a thumbnail of an image. It overscales and crops to fit the target + * box. + * + * @param string $src_file + * @param string $dest_file + * @param int $width + * @param int $height + * @return boolean + */ function mkthumbnail($src_file, $dest_file, $width, $height) { + list($src_width, $src_height) = getimagesize($src_file); + $im = imagecreatefromstring(file_get_contents($src_file)); $dest = imagecreatetruecolor($width, $height); - // TODO + + $scale = max( $width/$src_width, $height/$src_height ); // overscale + crop + + print_r($scale); + + $box_w = $width/$scale; + $box_h = $height/$scale; + + $box_xoff = floor(($src_width - $box_w)/2); + $box_yoff = floor(($src_height - $box_h)/2); + + print_r(array( + $dest, $im, + 0, 0, + $box_xoff, $box_yoff, + $width, $height, $box_w, $box_h + )); + + imagecopyresampled( + $dest, $im, + 0, 0, + $box_xoff, $box_yoff, + $width, $height, $box_w, $box_h + ); return imagejpeg($dest, $dest_file); } @@ -44,6 +84,10 @@ function is_image($sz) { return in_array(strtolower(str_ext($sz)), ['jpg', 'png', 'jpeg']); } +function hesc($sz) { + return @htmlentities($sz, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); +} + class CProject { private $dir; @@ -79,27 +123,74 @@ class CProject { public function write() { - // Build file mapping - // Generate image thumbnails - // Copy data files to wwwroot + foreach($this->images as $idx => $image) { + $outfile = BASEDIR.'wwwroot/srv/'.$this->projname.'_'.$idx; + copy($this->dir.$image, $outfile.'.'.str_ext($image)); + + mkthumbnail($outfile.'.'.str_ext($image), $outfile.'_thumb.jpg', PAGE_THUMB_W, PAGE_THUMB_H); + } + + // Copy downloads to wwwroot + + foreach($this->downloads as $idx => $filename) { + copy($this->dir.$filename, BASEDIR.'wwwroot/srv/'.$filename); + } // Generate index page + + ob_start(); + $this->index(); + $idxfile = ob_get_clean(); + file_put_contents(BASEDIR.'wwwroot/'.$this->projname.'.html', $idxfile); + } + + public function index() { +?> + + + + +=nl2br(hesc($this->longdesc))?>
+ + images)) { ?> +