summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-07-11 15:01:02 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-07-11 15:01:02 +0300
commitc2f382aba86aaebb9806ff1b43c1af69992e9a10 (patch)
treeaee205721fd675926c5e7163eec0dddc448f7813 /lib
parent24982a48f570b89e537850dda4a4d1ac33ea919f (diff)
support dark mode for images with alpha channel
Diffstat (limited to 'lib')
-rw-r--r--lib/MyParsedown.php1
-rw-r--r--lib/markup.php11
-rw-r--r--lib/posts.php3
3 files changed, 11 insertions, 4 deletions
diff --git a/lib/MyParsedown.php b/lib/MyParsedown.php
index c2c0112..11e86d6 100644
--- a/lib/MyParsedown.php
+++ b/lib/MyParsedown.php
@@ -99,6 +99,7 @@ class MyParsedown extends ParsedownHighlight {
nolabel: $opts['nolabel'],
align: $opts['align'],
padding_top: round($h / $w * 100, 4),
+ may_have_alpha: $image->imageMayHaveAlphaChannel(),
url: $image_url,
direct_url: $image->getDirectUrl(),
diff --git a/lib/markup.php b/lib/markup.php
index 52ccf24..2f25c6c 100644
--- a/lib/markup.php
+++ b/lib/markup.php
@@ -16,12 +16,15 @@ class markup {
return $text;
}
- public static function htmlRetinaFix(string $html): string {
+ public static function htmlImagesFix(string $html, bool $is_retina, string $user_theme): string {
global $config;
+ $is_dark_theme = $user_theme === 'dark';
return preg_replace_callback(
- '/('.preg_quote($config['uploads_host'], '/').'\/\w{8}\/p)(\d+)x(\d+)(\.jpg)/',
- function($match) {
- return $match[1].(intval($match[2])*2).'x'.(intval($match[3])*2).$match[4];
+ '/('.preg_quote($config['uploads_host'], '/').'\/\w{8}\/)([ap])(\d+)x(\d+)(\.jpg)/',
+ function($match) use ($is_retina, $is_dark_theme) {
+ $mult = $is_retina ? 2 : 1;
+ $is_alpha = $match[2] == 'a';
+ return $match[1].$match[2].(intval($match[3])*$mult).'x'.(intval($match[4])*$mult).($is_alpha && $is_dark_theme ? '_dark' : '').$match[5];
},
$html
);
diff --git a/lib/posts.php b/lib/posts.php
index bf8d149..1537749 100644
--- a/lib/posts.php
+++ b/lib/posts.php
@@ -23,6 +23,9 @@ class posts {
return (int)$db->result($db->query($sql, $tag_id));
}
+ /**
+ * @return Post[]
+ */
public static function getPosts(int $offset = 0, int $count = -1, bool $include_hidden = false): array {
$db = getDb();
$sql = "SELECT * FROM posts";