PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/imagekit/src/lmbAbstractImageFilter.class.php

https://github.com/syfisher/limb
PHP | 87 lines | 67 code | 7 blank | 13 comment | 9 complexity | 8f96fe615220cab69b6e489977920756 MD5 | raw file
  1. <?php
  2. /*
  3. * Limb PHP Framework
  4. *
  5. * @link http://limb-project.com
  6. * @copyright Copyright &copy; 2004-2009 BIT(http://bit-creative.com)
  7. * @license LGPL http://www.gnu.org/copyleft/lesser.html
  8. */
  9. lmb_require('limb/imagekit/src/lmbAbstractImageContainer.class.php');
  10. /**
  11. * Abstract image filter
  12. *
  13. * @package imagekit
  14. * @version $Id: lmbAbstractImageFilter.class.php 8065 2010-01-20 04:18:19Z korchasa $
  15. */
  16. abstract class lmbAbstractImageFilter
  17. {
  18. protected $params;
  19. function __construct($params)
  20. {
  21. $this->params = $params;
  22. }
  23. function parseHexColor($hex)
  24. {
  25. $length = strlen($hex);
  26. $color['red'] = hexdec(substr($hex, $length - 6, 2));
  27. $color['green'] = hexdec(substr($hex, $length - 4, 2));
  28. $color['blue'] = hexdec(substr($hex, $length - 2, 2));
  29. return $color;
  30. }
  31. function calcSize($src_w, $src_h, $dst_w, $dst_h, $preserve_aspect_ratio = true, $save_min_size = false)
  32. {
  33. $w = $dst_w;
  34. $h = $dst_h;
  35. if($preserve_aspect_ratio)
  36. {
  37. $scale = (float)1;
  38. $scale_w = (float)$dst_w / (float)$src_w;
  39. $scale_h = (float)$dst_h / (float)$src_h;
  40. if($scale_w > 1 && $scale_h > 1)
  41. {
  42. if($save_min_size)
  43. $scale = 1;
  44. elseif($scale_w > $scale_h)
  45. $scale = $scale_h;
  46. else
  47. $scale = $scale_w;
  48. }
  49. elseif($scale_w < 1 && $scale_h < 1)
  50. {
  51. if($scale_w > $scale_h)
  52. $scale = $scale_h;
  53. else
  54. $scale = $scale_w;
  55. }
  56. elseif($scale_w < 1)
  57. $scale = $scale_w;
  58. else
  59. $scale = $scale_h;
  60. $w = (int) round($src_w * $scale);
  61. $h = (int) round($src_h * $scale);
  62. }
  63. elseif($save_min_size)
  64. {
  65. if($dst_w > $src_w)
  66. $w = $src_w;
  67. if($dst_h > $src_h)
  68. $h = $src_h;
  69. }
  70. return array($w, $h);
  71. }
  72. function getParam($name, $default = null)
  73. {
  74. $param = $default;
  75. if(isset($this->params[$name]))
  76. $param = $this->params[$name];
  77. return $param;
  78. }
  79. abstract function apply(lmbAbstractImageContainer $container);
  80. }