2 #include <glib/gstdio.h>
6 void resize(gchar *orig, gchar *thumb, gchar *size)
9 int oval = g_stat(orig, &oinfo);
10 int tval = g_stat(thumb, &tinfo);
11 if (tval || (!oval && oinfo.st_mtime > tinfo.st_mtime)) {
13 gchar *argv[] = {"convert", "-resize", size, orig, thumb, NULL};
14 g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
15 NULL, NULL, NULL, NULL, NULL, NULL);
19 GList *gen_thumbs(GList *images)
21 if (!g_file_test("large", G_FILE_TEST_EXISTS)) g_mkdir("large", 0775);
22 if (!g_file_test("small", G_FILE_TEST_EXISTS)) g_mkdir("small", 0775);
23 if (!g_file_test("thumb", G_FILE_TEST_EXISTS)) g_mkdir("thumb", 0775);
24 for (GList *cur = images; cur; cur = cur->next) {
25 gchar *name = cur->data;
26 gchar *large = g_build_filename("large", name, NULL);
27 gchar *small = g_build_filename("small", name, NULL);
28 gchar *thumb = g_build_filename("thumb", name, NULL);
29 resize(large, thumb, "200x200");
30 resize(large, small, "800x800");
38 GList *read_dir(gchar *dirname)
40 GDir *dir = g_dir_open(dirname, 0, NULL);
41 const gchar *name = NULL;
43 while ((name = g_dir_read_name(dir)))
44 images = g_list_prepend(images, g_strdup(name));
45 images = g_list_sort(images, (GCompareFunc)g_strcmp0);
51 ct_print_header("text/html", NULL);
53 const gchar *path = ct_get_path_info();
54 const gchar *query = ct_get_query_string();
56 GList *thumbs = gen_thumbs(read_dir("large"));
58 if (!path || g_str_equal(path, "/"))
60 else if (g_str_equal(path, "/head"))
62 else if (g_str_equal(path, "/nav"))
63 frame_nav(FALSE, thumbs);
64 else if (g_str_equal(path, "/noframe"))
65 frame_nav(TRUE, thumbs);
66 else if (g_str_equal(path, "/show_small"))
67 frame_show("small", "show_large", query);
68 else if (g_str_equal(path, "/show_large"))
69 frame_show("large", "show_small", query);