Browse Source

feature:image module accepts format or bypass of caching

master
Dominik Schmidt-Philipp 1 week ago
parent
commit
9941a4f7dd
2 changed files with 24 additions and 6 deletions
  1. +14
    -3
      app/modules/cachedimage.php
  2. +10
    -3
      app/modules/ceimage.php

+ 14
- 3
app/modules/cachedimage.php View File

public $default_width = 500; public $default_width = 500;
public $format; public $format;
public $quality; public $quality;
private $usecache = true;


function __construct($path) {
function __construct($path,$format=false) {
$f3 = \Base::instance(); $f3 = \Base::instance();
$this->original = $path; $this->original = $path;
$this->format = $f3->get('cachedImageFormat') ? : 'jpeg'; $this->format = $f3->get('cachedImageFormat') ? : 'jpeg';
$this->quality = $f3->get('cachedImageQuality') ? : false; $this->quality = $f3->get('cachedImageQuality') ? : false;

if (is_string($format)) {
$format = strtolower($format);
if (in_array($format, ['png','jpg','jpeg'])) {
$this->format = $format;
} elseif ($format == "nocache") {
$this->usecache = false;
}
}
if ($this->quality === false) { if ($this->quality === false) {
switch($this->format) { switch($this->format) {
case 'png': case 'png':
} }
} }
function get_src($inwidth = 500) {
function get_src($inwidth = false) {
$f3 = \Base::instance(); $f3 = \Base::instance();
if($this->is_image($this->original) && TRUE) {
if($this->is_image($this->original) && $this->usecache) {
$info = pathinfo($this->original); $info = pathinfo($this->original);
$fn = basename($this->original,'.'.$info['extension']); $fn = basename($this->original,'.'.$info['extension']);
$width = $inwidth ? $inwidth : $this->default_width; $width = $inwidth ? $inwidth : $this->default_width;

+ 10
- 3
app/modules/ceimage.php View File

$body = $this->b; $body = $this->b;
$key=$request[1]; $key=$request[1];
$image=""; $image="";
$width=null;
$format=false;
$new=""; $new="";
// see if we can find image // see if we can find image
$class = 'left'; $class = 'left';
} }
if (isset($request[3])) { if (isset($request[3])) {
$width=self::is_width($request[3]) ? $request[3] : null;
if (self::is_width($request[3])) {
$width=$request[3];
} elseif (in_array($request[3], ['png','jpg','jpeg','nocache'])) {
$format=$request[3];
}
} }


if ($image) { if ($image) {
: "portrait" : "portrait"
; ;
unset($img); unset($img);
$cached = new CachedImage($image);
$cached = new CachedImage($image,$format);


// identify if caption contains a copyright note // identify if caption contains a copyright note
// if so, indicate with a class // if so, indicate with a class
."</div>", ."</div>",
$class, $class,
$ratio, $ratio,
(isset($width) ? "style=\"flex-basis:$width;\"" : ''),
($width ? "style=\"flex-basis:$width;\"" : ''),
$cached->get_src(1600), $cached->get_src(1600),
$cached->get_src(1600), $cached->get_src(1600),
$cached->get_src(1600), $cached->get_src(1600),

Loading…
Cancel
Save