page_image.auto_cache.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. //模板页的png显示缓存
  3. class page_image_auto_cache extends auto_cache{
  4. public function load($param)
  5. {
  6. $param=array("img"=>$param['img']);
  7. $key = $this->build_key(__CLASS__,$param);
  8. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  9. $image_str = $GLOBALS['cache']->get($key);
  10. if($image_str === false)
  11. {
  12. $img = $param['img'];
  13. $img_path = str_replace("./",get_domain().APP_ROOT."/",$img);
  14. require_once APP_ROOT_PATH."system/utils/es_image.php";
  15. $imagec = new es_image();
  16. $info = $imagec->getImageInfo($img);
  17. if($info['mime']=='image/png')
  18. {
  19. $image_str = "<span style='display:inline-block; width:".intval($info['width'])."px; height:".intval($info['height'])."px; background:url(".$img_path.") no-repeat; _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=".$img_path.", sizingMethod=scale);_background-image:none;'></span>";
  20. }
  21. else
  22. {
  23. $image_str = "<img src='".$img_path."' width='".intval($info['width'])."' height='".intval($info['height'])."' />";
  24. }
  25. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  26. $GLOBALS['cache']->set("PAGE_IMAGE_".$img,$image_str);
  27. }
  28. return $image_str;
  29. }
  30. public function rm($param)
  31. {
  32. $key = $this->build_key(__CLASS__,$param);
  33. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  34. $GLOBALS['cache']->rm($key);
  35. }
  36. public function clear_all()
  37. {
  38. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  39. $GLOBALS['cache']->clear();
  40. }
  41. }
  42. ?>