#include <glib.h>
+#include <glib/gstdio.h>
#include "html.h"
-const gchar *query_string;
+void resize(gchar *orig, gchar *thumb)
+{
+ gchar *argv[] = {"convert", "-resize", "200x200", orig, thumb, NULL};
+ /* god damn glib */
+ g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
+ NULL, NULL, NULL, NULL, NULL, NULL);
+}
-void ct_init()
+GList *gen_thumbs(GList *images)
{
- query_string = g_getenv("QUERY_STRING");
+ if (!g_file_test("thumbs", G_FILE_TEST_EXISTS))
+ g_mkdir("thumbs", 0644);
+ if (!g_file_test("images", G_FILE_TEST_EXISTS))
+ g_mkdir("images", 0644);
+ for (GList *cur = images; cur; cur = cur->next) {
+ gchar *name = cur->data;
+ gchar *thumb = g_strconcat("thumbs/", name, NULL);
+ gchar *image = g_strconcat("images/", name, NULL);
+ if (!g_file_test(thumb, G_FILE_TEST_EXISTS))
+ resize(image, thumb);
+ g_free(thumb);
+ g_free(image);
+ }
+ return images;
}
GList *read_dir(gchar *dirname)
GDir *dir = g_dir_open(dirname, 0, NULL);
const gchar *name = NULL;
GList *images = NULL;
- while ((name = g_dir_read_name(dir)))
- images = g_list_prepend(images, (gchar*)name);
- g_dir_close(dir);
+ while ((name = g_dir_read_name(dir))) {
+ g_message("got image %s", name);
+ images = g_list_prepend(images, g_strdup(name));
+ }
return images;
}
int main()
{
- ct_init();
-
header();
g_print("\n");
+ const gchar *query_string = g_getenv("QUERY_STRING");
if (query_string == NULL)
frame_index();
else if (g_str_equal(query_string, "noframe"))
- frame_nav(TRUE, read_dir("images"));
+ frame_nav(TRUE, gen_thumbs(read_dir("images")));
else if (g_str_equal(query_string, "nav"))
- frame_nav(FALSE, read_dir("images"));
+ frame_nav(FALSE, gen_thumbs(read_dir("images")));
else if (g_str_equal(query_string, "head"))
frame_head();
else if (g_str_equal(query_string, "content"))
<html>
<frameset rows="20, *">
<frame name="head" src="?head">
- <frameset cols="240,*">
+ <frameset cols="248,*">
<frame name="nav" src="?nav">
<frame name="content" src="?content">
</frameset>
[}]
-[void frame_nav(int square, GList *thumbs) {]
+[void frame_nav(int square, GList *images) {]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
</style>
</head>
<body>
- [for (GList *cur =thumbs; cur; cur = cur->next) {]
+ [for (GList *cur = images; cur; cur = cur->next) {]
<div class="align">
<a class="box" target="content"
[g_print("href=\"images/%s\"", (gchar*)cur->data);]
void frame_head();
-void frame_nav(int square, GList *thumbs);
+void frame_nav(int square, GList *images);
void frame_content();
--- /dev/null
+<html>
+</html>
--- /dev/null
+<html>
+ <frameset rows="20, *">
+ <frame name="head" src="head.php">
+ <frameset cols="240,*">
+ <frame name="nav" src="nav.php">
+ <frame name="content" src="content.php">
+ </frameset>
+ </frameset>
+</html>
--- /dev/null
+<?php
+ $jpgs = shell_exec("cd images && ls -1 *.jpg");
+ $jpgs = explode("\n", $jpgs);
+ foreach ($jpgs as $jpg) {
+ #imagecreatefromjpeg($jpg);
+
+
+ ### begin resize ###
+ list($sw, $sh) = getimagesize("images/$jpg");
+ $mw = 200;
+ $mh = 200;
+ if ($sw > $mw || $sh > $mh) {
+ if ($sw > $sh) {
+ $dw = $mw;
+ $dh = $sh*($mw/$sw);
+ }
+ if ($sh > $sw) {
+ $dh = $mh;
+ $dw = $sw*($mh/$sh);
+ }
+ } else {
+ $dw = $sw;
+ $dh = $sh;
+ }
+ $src_image = imagecreatefromjpeg("images/$jpg");
+ $dst_image = imagecreatetruecolor($dw, $dh);
+ imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
+ imagejpeg($dst_image, "thumbs/{$jpg}");
+ ### end resize ###
+
+ print("<br>".$jpg);
+ }
+?>
--- /dev/null
+<html>
+ <head>
+ <style>
+ body {
+ padding:0px;
+ margin:0px;
+ }
+ </style>
+ </head>
+ <body>
+ <center>
+ <a href="noframes.php" target="parent">No Frames</a>
+ </center>
+ </body>
+</html>
--- /dev/null
+<?php
+ header("Location: frames.php");
+?>
--- /dev/null
+<html>
+<head>
+<style>
+ .gallery_item_con {
+ text-decoration:none;
+ /*padding-top:5px;
+ padding-top:5px;*/
+ margin-top:5px;
+ margin-bottom:5px;
+ display:block;
+ width:210px;
+ text-align:center;
+ float:left;
+ }
+
+ .gallery_item {
+ text-decoration:none;
+ background-color:#f8fbFF;
+ border:solid 1px #B4C7F8;
+ /*padding-top:5px;
+ padding-top:5px;*/
+ padding:5px;
+ display:block;
+ /*height:210px;*/
+ text-align:center;
+ }
+ .gallery_item img {
+ border:none;
+ }
+ .gallery_item:hover {
+ color:#0D378D;
+ }
+</style>
+</head>
+<body>
+
+<?php
+$thumbs = shell_exec("cd thumbs && ls -1 *.jpg");
+$thumbs = explode("\n", $thumbs);
+array_pop($thumbs);
+foreach ($thumbs as $thumb) {
+ print("<div class=\"gallery_item_con\">\n");
+ print("\t<a class=\"gallery_item\" href=\"images/$thumb\" target=\"content\">\n");
+ print("\t\t<img src=\"thumbs/$thumb\">\n");
+ print("\t</a>\n");
+ print("</div>\n");
+}
+?>
+</body>
+</html>
--- /dev/null
+<html>
+<head>
+<style>
+ .gallery_item_con {
+ text-decoration:none;
+ /*padding-top:5px;
+ padding-top:5px;*/
+ margin:10px;
+ display:block;
+ height:210px;
+ width:210px;
+ text-align:center;
+ float:left;
+ }
+
+ .gallery_item {
+ text-decoration:none;
+ background-color:#f8fbFF;
+ border:solid 1px #B4C7F8;
+ /*padding-top:5px;
+ padding-top:5px;*/
+ padding:5px;
+ display:block;
+ /*height:210px;*/
+ text-align:center;
+ }
+ .gallery_item img {
+ border:none;
+ }
+ .gallery_item:hover {
+ color:#0D378D;
+ }
+</style>
+</head>
+<body>
+<center>
+ <a href="frames.php">Frames</a>
+</center>
+<?php
+$thumbs = shell_exec("cd thumbs && ls -1 *.jpg");
+$thumbs = explode("\n", $thumbs);
+array_pop($thumbs);
+foreach ($thumbs as $thumb) {
+ print("<div class=\"gallery_item_con\">\n");
+ print("\t<a class=\"gallery_item\" href=\"images/$thumb\">\n");
+ print("\t\t<img src=\"thumbs/$thumb\">\n");
+ print("\t</a>\n");
+ print("</div>\n");
+}
+?>
+</body>
+</html>