phpthumbof.snippet.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * pThumb
  4. * Copyright 2013-2014 Jason Grant
  5. *
  6. * Please see the GitHub page for documentation or to report bugs:
  7. * https://github.com/oo12/phpThumbOf
  8. *
  9. * Forked from phpThumbOf 1.4.0
  10. * Copyright 2009-2012 by Shaun McCormick <shaun@modx.com>
  11. *
  12. * pThumb is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the Free
  14. * Software Foundation; either version 2 of the License, or (at your option) any
  15. * later version.
  16. *
  17. * pThumb is distributed in the hope that it will be useful, but WITHOUT ANY
  18. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  19. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along with
  22. * phpThumbOf; if not, write to the Free Software Foundation, Inc., 59 Temple
  23. * Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. */
  26. /**
  27. *
  28. * @var modX $modx
  29. * @var array $scriptProperties
  30. * @var string $input
  31. * @var string|array $options
  32. *
  33. */
  34. if (empty($input)) { // Exit quietly if no file name given
  35. return;
  36. }
  37. $scriptProperties['debug'] = isset($debug) ? $debug : false;
  38. static $pt_settings = array();
  39. if (empty($pt_settings)) {
  40. if (!$modx->loadClass('phpThumbOf', MODX_CORE_PATH . 'components/phpthumbof/model/', true, true)) {
  41. $modx->log(modX::LOG_LEVEL_ERROR, '[pThumb] Could not load phpThumbOf class.');
  42. return $input;
  43. }
  44. }
  45. $pThumb = new phpThumbOf($modx, $pt_settings, $scriptProperties);
  46. $result = $pThumb->createThumbnail($input, $options);
  47. if (!empty($toPlaceholder) || $result['outputDims']) {
  48. if ($result['width'] === '' && $result['file'] && $dims = getimagesize($result['file']) ) {
  49. $result['width'] = $dims[0];
  50. $result['height'] = $dims[1];
  51. }
  52. if (!empty($toPlaceholder)) {
  53. $modx->setPlaceholders(array(
  54. $toPlaceholder => $result['src'],
  55. "$toPlaceholder.width" => $result['width'],
  56. "$toPlaceholder.height" => $result['height']
  57. ));
  58. $output = '';
  59. }
  60. if ($result['outputDims']) {
  61. $output = "src=\"{$result['src']}\"" . ($result['width'] ? " width=\"{$result['width']}\" height=\"{$result['height']}\"" : '');
  62. }
  63. }
  64. else {
  65. $output = $result['src'];
  66. }
  67. if ($debug && $result['success']) { // if debugging is on and createThumbnail was successful, log the debug info
  68. $pThumb->debugmsg(isset($pThumb->phpThumb->debugmessages) ? ':: Processed ::' : ":: Loaded from cache: {$result['src']}", true);
  69. }
  70. return $output;