mostly filebased Content Presentation System
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

46 行
1.2KB

  1. <?php
  2. namespace Modules;
  3. class CachedImage {
  4. public $original;
  5. public $cache_dir = "rsc/img_display/";
  6. public $default_width = 500;
  7. function __construct($path) {
  8. $this->original = $path;
  9. }
  10. function get_src($inwidth = 500) {
  11. $f3 = \Base::instance();
  12. if($this->is_image($this->original)) {
  13. $info = pathinfo($this->original);
  14. $fn = basename($this->original,'.'.$info['extension']);
  15. $width = $inwidth ? $inwidth : $this->default_width;
  16. $name = md5($this->original.$width);
  17. $name = sprintf("%s_%s.jpg",$fn,$name);
  18. $out = $this->cache_dir.$name;
  19. //if(!file_exists($this->original)) { $this->original='rsc/img/default.png'; }
  20. if(!file_exists($out)) {
  21. $img1 = new \Image($this->original);
  22. $img1->resize($width);
  23. $f3->write($out,$img1->dump('jpeg',75));
  24. }
  25. } else {
  26. $out = $this->original;
  27. }
  28. return $out;
  29. }
  30. function is_image($path) {
  31. $ex = explode('.',$path);
  32. $ext = array_pop($ex);
  33. return in_array(strtolower($ext),array( 'jpg', 'jpeg', 'png' ));
  34. }
  35. }