2 #include <glib/gstdio.h>
6 void resize(gchar *orig, gchar *thumb, gchar *size)
8 gchar *argv[] = {"convert", "-resize", size, orig, thumb, NULL};
10 g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
11 NULL, NULL, NULL, NULL, NULL, NULL);
14 GList *gen_thumbs(GList *images)
16 if (!g_file_test("large", G_FILE_TEST_EXISTS)) g_mkdir("large", 0775);
17 if (!g_file_test("small", G_FILE_TEST_EXISTS)) g_mkdir("small", 0775);
18 if (!g_file_test("thumb", G_FILE_TEST_EXISTS)) g_mkdir("thumb", 0775);
19 for (GList *cur = images; cur; cur = cur->next) {
20 gchar *name = cur->data;
21 gchar *large = g_build_filename("large", name, NULL);
22 gchar *small = g_build_filename("small", name, NULL);
23 gchar *thumb = g_build_filename("thumb", name, NULL);
24 if (!g_file_test(thumb, G_FILE_TEST_EXISTS)) {
25 resize(large, thumb, "200x200");
26 resize(large, small, "800x800");
35 GList *read_dir(gchar *dirname)
37 GDir *dir = g_dir_open(dirname, 0, NULL);
38 const gchar *name = NULL;
40 while ((name = g_dir_read_name(dir)))
41 images = g_list_prepend(images, g_strdup(name));
42 images = g_list_sort(images, (GCompareFunc)g_strcmp0);
48 ct_print_header("text/html", NULL);
50 const gchar *path = ct_get_path_info();
51 const gchar *query = ct_get_query_string();
53 GList *thumbs = gen_thumbs(read_dir("large"));
55 if (!path || g_str_equal(path, "/"))
57 else if (g_str_equal(path, "/head"))
59 else if (g_str_equal(path, "/nav"))
60 frame_nav(FALSE, thumbs);
61 else if (g_str_equal(path, "/noframe"))
62 frame_nav(TRUE, thumbs);
63 else if (g_str_equal(path, "/show_small"))
64 frame_show("small", "show_large", query);
65 else if (g_str_equal(path, "/show_large"))
66 frame_show("large", "show_small", query);