From 94a72f13f1a737e37668497fb7b862bb4ab1226c Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sun, 22 Nov 2009 00:29:30 +0000 Subject: [PATCH] Add old version of gallery using php --- gallery/gallery.c | 40 +++++++++++++++++++++-------- gallery/html.ct | 6 ++--- gallery/html.h | 2 +- gallery/old/content.php | 2 ++ gallery/old/frames.php | 9 +++++++ gallery/old/gen_thumbs.php | 33 ++++++++++++++++++++++++ gallery/old/head.php | 15 +++++++++++ gallery/old/index.php | 3 +++ gallery/old/nav.php | 50 ++++++++++++++++++++++++++++++++++++ gallery/old/noframes.php | 52 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 198 insertions(+), 14 deletions(-) create mode 100755 gallery/old/content.php create mode 100755 gallery/old/frames.php create mode 100755 gallery/old/gen_thumbs.php create mode 100755 gallery/old/head.php create mode 100755 gallery/old/index.php create mode 100755 gallery/old/nav.php create mode 100755 gallery/old/noframes.php diff --git a/gallery/gallery.c b/gallery/gallery.c index 537be3e..9b0e432 100644 --- a/gallery/gallery.c +++ b/gallery/gallery.c @@ -1,11 +1,31 @@ #include +#include #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) @@ -13,25 +33,25 @@ 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")) diff --git a/gallery/html.ct b/gallery/html.ct index 2b04615..4080fa3 100644 --- a/gallery/html.ct +++ b/gallery/html.ct @@ -9,7 +9,7 @@ Content-Type: text/html; charset=UTF-8 - + @@ -37,7 +37,7 @@ Content-Type: text/html; charset=UTF-8 [}] -[void frame_nav(int square, GList *thumbs) {] +[void frame_nav(int square, GList *images) {] @@ -74,7 +74,7 @@ Content-Type: text/html; charset=UTF-8 - [for (GList *cur =thumbs; cur; cur = cur->next) {] + [for (GList *cur = images; cur; cur = cur->next) {]
data);] diff --git a/gallery/html.h b/gallery/html.h index 85f95d4..2fd46e5 100644 --- a/gallery/html.h +++ b/gallery/html.h @@ -4,6 +4,6 @@ void frame_index(); void frame_head(); -void frame_nav(int square, GList *thumbs); +void frame_nav(int square, GList *images); void frame_content(); diff --git a/gallery/old/content.php b/gallery/old/content.php new file mode 100755 index 0000000..90531a4 --- /dev/null +++ b/gallery/old/content.php @@ -0,0 +1,2 @@ + + diff --git a/gallery/old/frames.php b/gallery/old/frames.php new file mode 100755 index 0000000..534caee --- /dev/null +++ b/gallery/old/frames.php @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/gallery/old/gen_thumbs.php b/gallery/old/gen_thumbs.php new file mode 100755 index 0000000..f3d925e --- /dev/null +++ b/gallery/old/gen_thumbs.php @@ -0,0 +1,33 @@ + $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("
".$jpg); + } +?> diff --git a/gallery/old/head.php b/gallery/old/head.php new file mode 100755 index 0000000..33b5ecd --- /dev/null +++ b/gallery/old/head.php @@ -0,0 +1,15 @@ + + + + + +
+ No Frames +
+ + diff --git a/gallery/old/index.php b/gallery/old/index.php new file mode 100755 index 0000000..f46b158 --- /dev/null +++ b/gallery/old/index.php @@ -0,0 +1,3 @@ + diff --git a/gallery/old/nav.php b/gallery/old/nav.php new file mode 100755 index 0000000..9c684b5 --- /dev/null +++ b/gallery/old/nav.php @@ -0,0 +1,50 @@ + + + + + + +\n"); + print("\t\n"); + print("\t\t\n"); + print("\t\n"); + print("
\n"); +} +?> + + diff --git a/gallery/old/noframes.php b/gallery/old/noframes.php new file mode 100755 index 0000000..a9656f7 --- /dev/null +++ b/gallery/old/noframes.php @@ -0,0 +1,52 @@ + + + + + +
+ Frames +
+\n"); + print("\t\n"); + print("\t\t\n"); + print("\t\n"); + print("\n"); +} +?> + + -- 2.43.2