Allow clicking through to full quality images
[pics.git] / app.php
1 <html>
2 <head>
3 <link rel="stylesheet" href="style.css">
4 <link rel="alternate" title="Pics dot JC" type="application/rss+xml" href="/rss.xml">
5 </head>
6
7 <body>
8 <main>
9 <a href='upload'>Upload</a>
10 <?php
11
12 require_once __DIR__ . '/db.php';
13
14 $db = get_db();
15 $posts = $db->query('SELECT
16 p.ID as POST_ID,
17 p.TIMESTAMP,
18 pi.ID as PIC_ID,
19 pi.MIME_TYPE,
20 pi.PIC_B64,
21 c.BODY
22 FROM posts p
23 JOIN pics pi on p.id = pi.post_id
24 JOIN comments c on p.id = c.post_id
25 ORDER BY p.TIMESTAMP DESC');
26 while ($post = $posts->fetchArray()) {
27 $mime_type = $post['MIME_TYPE'];
28 $file_b64 = $post['PIC_B64'];
29 $post_id = $post['POST_ID'];
30 $pic_id = $post['PIC_ID'];
31 $comment_text = $post['BODY'];
32 $img = new Imagick();
33 $img->readImageBlob(base64_decode($file_b64));
34 $img->setImageCompressionQuality(85);
35 $img->adaptiveResizeImage(480, 0);
36 $compressed_b64 = base64_encode($img->getImageBlob());
37
38 echo "<div id='post-{$post_id}'>";
39
40 echo "<a href='pic/{$pic_id}'> <img src='data:{$mime_type};base64,{$compressed_b64}' alt='$'/></a>";
41 echo "<p>{$comment_text}</p>";
42 echo '</div>';
43 }
44 ?>
45 </main>
46 </body>
47 </html>