Procházet zdrojové kódy

feature:image module accepts format or bypass of caching

master
Dominik Schmidt-Philipp před 1 týdnem
rodič
revize
9941a4f7dd
2 změnil soubory, kde provedl 24 přidání a 6 odebrání
  1. +14
    -3
      app/modules/cachedimage.php
  2. +10
    -3
      app/modules/ceimage.php

+ 14
- 3
app/modules/cachedimage.php Zobrazit soubor

@@ -9,12 +9,23 @@ class CachedImage {
public $default_width = 500;
public $format;
public $quality;
private $usecache = true;

function __construct($path) {
function __construct($path,$format=false) {
$f3 = \Base::instance();
$this->original = $path;
$this->format = $f3->get('cachedImageFormat') ? : 'jpeg';
$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) {
switch($this->format) {
case 'png':
@@ -28,9 +39,9 @@ class CachedImage {
}
}
function get_src($inwidth = 500) {
function get_src($inwidth = false) {
$f3 = \Base::instance();
if($this->is_image($this->original) && TRUE) {
if($this->is_image($this->original) && $this->usecache) {
$info = pathinfo($this->original);
$fn = basename($this->original,'.'.$info['extension']);
$width = $inwidth ? $inwidth : $this->default_width;

+ 10
- 3
app/modules/ceimage.php Zobrazit soubor

@@ -32,6 +32,8 @@ class CEimage
$body = $this->b;
$key=$request[1];
$image="";
$width=null;
$format=false;
$new="";
// see if we can find image
@@ -59,7 +61,11 @@ class CEimage
$class = 'left';
}
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) {
@@ -74,7 +80,8 @@ class CEimage
: "portrait"
;
unset($img);
$cached = new CachedImage($image);
$cached = new CachedImage($image,$format);

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

Načítá se…
Zrušit
Uložit