Add sixel support
This commit is contained in:
parent
0982ded5a1
commit
3fd9a57ec5
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$conf['render_sixel'] = 0;
|
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$meta['render_sixel'] = array('onoff');
|
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$lang['render_sixel'] = "[Experimental] Enables sixel image rendering. Requires the Imagick PHP extension.";
|
|
@ -1,7 +1,7 @@
|
||||||
base ansi
|
base ansi
|
||||||
author JP Savard
|
author JP Savard
|
||||||
email yuki@a39.ca
|
email yuki@a39.ca
|
||||||
date 2025-05-27
|
date 2025-05-30
|
||||||
name ANSI/VT100 text renderer
|
name ANSI/VT100 text renderer
|
||||||
desc Renders pages as text with ANSI/VT100 escape codes.
|
desc Renders pages as text with ANSI/VT100 escape codes.
|
||||||
url https://a39.dev/a39/dokuwiki-plugin-ansi
|
url https://a39.dev/a39/dokuwiki-plugin-ansi
|
||||||
|
|
67
renderer.php
67
renderer.php
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use dokuwiki\ChangeLog\MediaChangeLog;
|
||||||
|
use dokuwiki\File\MediaResolver;
|
||||||
use dokuwiki\File\PageResolver;
|
use dokuwiki\File\PageResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -511,20 +513,72 @@ class renderer_plugin_ansi extends Doku_Renderer
|
||||||
public function internalmedia($src, $title = null, $align = null, $width = null,
|
public function internalmedia($src, $title = null, $align = null, $width = null,
|
||||||
$height = null, $cache = null, $linking = null, $return = false)
|
$height = null, $cache = null, $linking = null, $return = false)
|
||||||
{
|
{
|
||||||
$this->doc .= "{{" . $src . "}}";
|
global $ID;
|
||||||
|
|
||||||
|
if (strpos($src, '#') !== false) {
|
||||||
|
[$src, $hash] = sexplode('#', $src, 2);
|
||||||
|
}
|
||||||
|
$src = (new MediaResolver($ID))->resolveId($src, $this->date_at, true);
|
||||||
|
$exists = media_exists($src);
|
||||||
|
|
||||||
|
$noLink = false;
|
||||||
|
$render = $linking != 'linkonly';
|
||||||
|
$render = $render && $exists;
|
||||||
|
$render = $render && class_exists("Imagick");
|
||||||
|
$render = $render && $this->getConf("render_sixel");
|
||||||
|
|
||||||
|
[$ext, $mime] = mimetype($src, false);
|
||||||
|
if (str_starts_with($mime, 'image') && $render)
|
||||||
|
{
|
||||||
|
$url = mediaFN($src, $this->_getLastMediaRevisionAt($src));
|
||||||
|
$image = new Imagick($url);
|
||||||
|
// todo: resize
|
||||||
|
if($width || $height) $image->thumbnailImage($width, $height);
|
||||||
|
$image->setImageFormat('sixel');
|
||||||
|
$ret = $image->getImageBlob();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$url = ml($src,
|
||||||
|
[
|
||||||
|
'id' => $ID,
|
||||||
|
'cache' => $cache,
|
||||||
|
'rev' => $this->_getLastMediaRevisionAt($src)
|
||||||
|
],
|
||||||
|
true
|
||||||
|
);
|
||||||
|
if(is_array($title)) $title = $title['title'];
|
||||||
|
if($title) $title = "\xF0\x9F\x96\xBC\xEF\xB8\x8F ".$title;
|
||||||
|
else $title = "\xF0\x9F\x96\xBC\xEF\xB8\x8F";
|
||||||
|
$ret = self::CSI.($exists ? "35" : "31") . ";4m" .$this->_formatLink($src, $this->_getFullLink($url), $title) . self::CSI."24;39m";
|
||||||
|
}
|
||||||
|
if($return) return $ret;
|
||||||
|
else $this->doc .= $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
public function externalmedia($src, $title = null, $align = null, $width = null,
|
public function externalmedia($src, $title = null, $align = null, $width = null,
|
||||||
$height = null, $cache = null, $linking = null, $return = false)
|
$height = null, $cache = null, $linking = null, $return = false)
|
||||||
{
|
{
|
||||||
$this->doc .= "{{" . $src . "}}";
|
if($title) $title = "\xF0\x9F\x96\xBC\xEF\xB8\x8F ".$title;
|
||||||
|
else $title = "\xF0\x9F\x96\xBC\xEF\xB8\x8F";
|
||||||
|
|
||||||
|
$ret = self::CSI."95;4m" . $this->_formatLink($src, $src, $title) . self::CSI."24;39m";
|
||||||
|
|
||||||
|
if($return) return $ret;
|
||||||
|
else $this->doc .= $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function _media($src, $title = null, $align = null, $width = null,
|
||||||
|
$height = null, $cache = null, $linking = null, $return = false)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
public function rss($url, $params)
|
public function rss($url, $params)
|
||||||
{
|
{
|
||||||
$this->doc .= "{{rss>" . $url . "}}" . DOKU_LF;
|
$this->doc .= "{{rss>" . $url . "}}" . DOKU_LF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
|
@ -647,4 +701,11 @@ class renderer_plugin_ansi extends Doku_Renderer
|
||||||
{
|
{
|
||||||
return self::OSC."8;;" . $url . self::ST . $name . ($id == $name ? "" : " [" . $id . "]") . self::OSC."8;;" . self::ST;
|
return self::OSC."8;;" . $url . self::ST . $name . ($id == $name ? "" : " [" . $id . "]") . self::OSC."8;;" . self::ST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function _getLastMediaRevisionAt($media_id)
|
||||||
|
{
|
||||||
|
if (!$this->date_at || media_isexternal($media_id)) return '';
|
||||||
|
$changelog = new MediaChangeLog($media_id);
|
||||||
|
return $changelog->getLastRevisionAt($this->date_at);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue