asset_image_renderer.class.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Process image resources. I.e. png, jpeg, etc.
  4. *
  5. * @copyright (c) 2011 University of Geneva
  6. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  7. * @author Laurent Opprecht
  8. */
  9. class AssetImageRenderer extends AssetRenderer
  10. {
  11. /**
  12. *
  13. * @param HttpResource $asset
  14. */
  15. public function render($asset)
  16. {
  17. if (! $asset->is_image())
  18. {
  19. return false;
  20. }
  21. global $THEME;
  22. $url = $asset->url();
  23. $title = $asset->title();
  24. $title = $title ? $title : $asset->name();
  25. $size = (int) $asset->config('size');
  26. $size = (24 <= $size && $size <= 800) ? $size : 300;
  27. $embed = <<<EOT
  28. <div style="text-align:center"><a href="$url"><img src="{$url}" width="$size" alt="{$title}" title="{$title}"></a></div>
  29. EOT;
  30. $result = array();
  31. $result[self::URL] = $url;
  32. $result[self::EMBED_SNIPPET] = $embed;
  33. $result[self::TITLE] = $title;
  34. $result[self::THUMBNAIL] = $url;
  35. return $result;
  36. }
  37. }