svg.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Preview;
  9. if (extension_loaded('imagick')) {
  10. class SVG extends Provider {
  11. public function getMimeType() {
  12. return '/image\/svg\+xml/';
  13. }
  14. public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) {
  15. try{
  16. $svg = new \Imagick();
  17. $svg->setResolution($maxX, $maxY);
  18. $content = stream_get_contents($fileview->fopen($path, 'r'));
  19. if(substr($content, 0, 5) !== '<?xml') {
  20. $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
  21. }
  22. $svg->readImageBlob($content);
  23. $svg->setImageFormat('jpg');
  24. } catch (\Exception $e) {
  25. \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
  26. return false;
  27. }
  28. //new image object
  29. $image = new \OC_Image($svg);
  30. //check if image object is valid
  31. return $image->valid() ? $image : false;
  32. }
  33. }
  34. \OC\Preview::registerProvider('OC\Preview\SVG');
  35. }