]> Pileus Git - ~andy/ct/commitdiff
Add old version of gallery using php
authorAndy Spencer <andy753421@gmail.com>
Sun, 22 Nov 2009 00:29:30 +0000 (00:29 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 22 Nov 2009 00:29:30 +0000 (00:29 +0000)
gallery/gallery.c
gallery/html.ct
gallery/html.h
gallery/old/content.php [new file with mode: 0755]
gallery/old/frames.php [new file with mode: 0755]
gallery/old/gen_thumbs.php [new file with mode: 0755]
gallery/old/head.php [new file with mode: 0755]
gallery/old/index.php [new file with mode: 0755]
gallery/old/nav.php [new file with mode: 0755]
gallery/old/noframes.php [new file with mode: 0755]

index 537be3e7ea8c692e9493f6b5b47e1570c77e5146..9b0e43231100b5163099159649725a554cf06f76 100644 (file)
@@ -1,11 +1,31 @@
 #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)
@@ -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"))
index 2b04615bdf45ebdae061e1edda2ff62f4b8dd5d4..4080fa30f9c1c005142f3917fcf95a77f78c69ea 100644 (file)
@@ -9,7 +9,7 @@ Content-Type: text/html; charset=UTF-8
 <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>
@@ -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) {]
 <!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">
@@ -74,7 +74,7 @@ Content-Type: text/html; charset=UTF-8
                </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);]
index 85f95d47683d535505af935b754546278de7c1ab..2fd46e5ef0f8b024525994b28257c489880ecd80 100644 (file)
@@ -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 (executable)
index 0000000..90531a4
--- /dev/null
@@ -0,0 +1,2 @@
+<html>
+</html>
diff --git a/gallery/old/frames.php b/gallery/old/frames.php
new file mode 100755 (executable)
index 0000000..534caee
--- /dev/null
@@ -0,0 +1,9 @@
+<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>
diff --git a/gallery/old/gen_thumbs.php b/gallery/old/gen_thumbs.php
new file mode 100755 (executable)
index 0000000..f3d925e
--- /dev/null
@@ -0,0 +1,33 @@
+<?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);
+       }
+?>
diff --git a/gallery/old/head.php b/gallery/old/head.php
new file mode 100755 (executable)
index 0000000..33b5ecd
--- /dev/null
@@ -0,0 +1,15 @@
+<html>
+       <head>
+               <style>
+                       body {
+                               padding:0px;
+                               margin:0px;
+                       }
+               </style>
+       </head>
+       <body>
+               <center>
+                       <a href="noframes.php" target="parent">No Frames</a>
+               </center>
+       </body>
+</html>
diff --git a/gallery/old/index.php b/gallery/old/index.php
new file mode 100755 (executable)
index 0000000..f46b158
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+       header("Location: frames.php"); 
+?>
diff --git a/gallery/old/nav.php b/gallery/old/nav.php
new file mode 100755 (executable)
index 0000000..9c684b5
--- /dev/null
@@ -0,0 +1,50 @@
+<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>
diff --git a/gallery/old/noframes.php b/gallery/old/noframes.php
new file mode 100755 (executable)
index 0000000..a9656f7
--- /dev/null
@@ -0,0 +1,52 @@
+<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>