Display posts, not pics
[pics.git] / index.php
... / ...
CommitLineData
1<html>
2<a href='upload.php'>Upload</a>
3<?php
4
5require_once __DIR__ . '/db.php';
6
7$db = get_db();
8$posts = $db->query('SELECT
9 p.ID, p.TIMESTAMP, pi.MIME_TYPE, pi.PIC_B64, c.BODY
10 FROM posts p
11 JOIN pics pi on p.id = pi.post_id
12 JOIN comments c on p.id = c.post_id
13 ORDER BY p.TIMESTAMP DESC');
14while ($post = $posts->fetchArray()) {
15 $mime_type = $post['MIME_TYPE'];
16 $file_b64 = $post['PIC_B64'];
17 $post_id = $post['ID'];
18 $comment_text = $post['BODY'];
19 $img = new Imagick();
20 $img->readImageBlob(base64_decode($file_b64));
21 $img->setImageCompressionQuality(85);
22 $img->adaptiveResizeImage(480, 0);
23 $compressed_b64 = base64_encode($img->getImageBlob());
24
25 echo "<div id='post-{$post_id}'>";
26
27 echo "<img src='data:{$mime_type};base64,{$compressed_b64}' alt='$'/>";
28 echo "<p>{$comment_text}</p>";
29 echo '</div>';
30}
31?>
32<div>footer</div>
33</html>