Browse Source

make cached image format configuarble through main.cfg

master
Dom SP 3 years ago
parent
commit
136b65931a
1 changed files with 18 additions and 2 deletions
  1. +18
    -2
      app/modules/cachedimage.php

+ 18
- 2
app/modules/cachedimage.php View File

public $original; public $original;
public $cache_dir = "tmp/"; public $cache_dir = "tmp/";
public $default_width = 500; public $default_width = 500;
public $format;
public $quality;


function __construct($path) { function __construct($path) {
$f3 = \Base::instance();
$this->original = $path; $this->original = $path;
$this->format = $f3->get('cachedImageFormat') ? : 'jpeg';
$this->quality = $f3->get('cachedImageQuality') ? : false;
if ($this->quality === false) {
switch($this->format) {
case 'png':
$this->quality = 6;
break;
case 'jpg':
case 'jpeg':
$this->quality = 75;
break;
}
}
} }
function get_src($inwidth = 500) { function get_src($inwidth = 500) {
$width = $inwidth ? $inwidth : $this->default_width; $width = $inwidth ? $inwidth : $this->default_width;
$name = md5($this->original.$width); $name = md5($this->original.$width);
$name = sprintf("%s_%s.jpg",$fn,$name);
$name = sprintf("%s_%s.%s",$fn,$name,$this->format);
$out = $this->cache_dir.$name; $out = $this->cache_dir.$name;
if(!file_exists($out)) { if(!file_exists($out)) {
$img1 = new \Image($this->original); $img1 = new \Image($this->original);
$img1->resize($width); $img1->resize($width);
$f3->write($out,$img1->dump('jpeg',75));
$f3->write($out,$img1->dump($this->format,$this->quality));
unset($img1); unset($img1);
} }
} else { } else {

Loading…
Cancel
Save