PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/mod_artsexylightbox/artsexylightbox/library/asido/class.driver.imagick_shell_hack.php

https://github.com/groovyobject/ChoicePoolsv1
PHP | 130 lines | 62 code | 22 blank | 46 comment | 5 complexity | 7337704f194dadc4b592b4f9792936a7 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, GPL-3.0
  1. <?php
  2. /**
  3. * @author Kaloyan K. Tsvetkov <kaloyan@kaloyan.info>
  4. * @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License Version 2.1
  5. * @package Asido
  6. * @subpackage Asido.Driver.Imagick_Shell
  7. * @version $Id: class.driver.imagick_shell_hack.php 7 2007-04-09 21:09:09Z mrasnika $
  8. */
  9. /////////////////////////////////////////////////////////////////////////////
  10. /**
  11. * @see Asido_Driver_Imagick_Shell
  12. */
  13. require_once ASIDO_DIR . "/class.driver.imagick_shell.php";
  14. /////////////////////////////////////////////////////////////////////////////
  15. /**
  16. * Asido "Imagick" driver (via shell) with some of the unsupported methods hacked via some work-arounds.
  17. *
  18. * @package Asido
  19. * @subpackage Asido.Driver.Imagick_Shell
  20. */
  21. Class Asido_Driver_Imagick_Shell_Hack Extends Asido_Driver_Imagick_Shell {
  22. /**
  23. * Rotate the image clockwise
  24. *
  25. * @param Asido_TMP &$tmp
  26. * @param float $angle
  27. * @param Asido_Color &$color
  28. * @return boolean
  29. * @access protected
  30. */
  31. function __rotate(&$tmp, $angle, &$color) {
  32. // skip full loops
  33. //
  34. if (($angle % 360) == 0) {
  35. return true;
  36. }
  37. $a = $tmp->image_height;
  38. $b = $tmp->image_width;
  39. // do the virtual `border`
  40. //
  41. $c = $a * cos(deg2rad($angle)) * sin(deg2rad($angle));
  42. $d = $b * cos(deg2rad($angle)) * sin(deg2rad($angle));
  43. // do the rest of the math
  44. //
  45. $a2 = $b * sin(deg2rad($angle)) + $a * cos(deg2rad($angle));
  46. $b2 = $a * sin(deg2rad($angle)) + $b * cos(deg2rad($angle));
  47. $a3 = 2 * $d + $a;
  48. $b3 = 2 * $c + $b;
  49. $a4 = $b3 * sin(deg2rad($angle)) + $a3 * cos(deg2rad($angle));
  50. $b4 = $a3 * sin(deg2rad($angle)) + $b3 * cos(deg2rad($angle));
  51. // create the `border` canvas
  52. //
  53. $t = $this->__canvas(ceil($b + 2*$c), ceil($a + 2*$d), $color);
  54. // copy the image
  55. //
  56. $cmd = $this->__command(
  57. 'composite',
  58. " -geometry {$b}x{$a}+" . ceil($c) . "+" . ceil($d) . " "
  59. . escapeshellarg(realpath($tmp->target))
  60. . " "
  61. . escapeshellarg(realpath($t->target))
  62. . " "
  63. . escapeshellarg(realpath($t->target))
  64. );
  65. exec($cmd, $result, $errors);
  66. if ($errors) {
  67. return false;
  68. }
  69. // rotate the whole thing
  70. //
  71. $cmd = $this->__command(
  72. 'convert',
  73. " -rotate {$angle} "
  74. . escapeshellarg(realpath($t->target))
  75. . " "
  76. . escapeshellarg(realpath($t->target))
  77. );
  78. exec($cmd, $result, $errors);
  79. if ($errors) {
  80. return false;
  81. }
  82. // `final` result
  83. //
  84. $cmd = $this->__command(
  85. 'convert',
  86. " -crop " . ceil($b2) . "x" . ceil($a2) . "+" . ceil(($b4 - $b2)/2) . "+" . ceil(($a4 - $a2)/2)
  87. . " "
  88. . escapeshellarg(realpath($t->target))
  89. . " TIF:"
  90. // ^
  91. // GIF saving hack
  92. . escapeshellarg(realpath($t->target))
  93. );
  94. exec($cmd, $result, $errors);
  95. if ($errors) {
  96. return false;
  97. }
  98. $this->__destroy_target($tmp);
  99. $tmp->target = $t->target;
  100. $tmp->image_width = $b2;
  101. $tmp->image_height = $a2;
  102. return true;
  103. }
  104. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  105. //--end-of-class--
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. ?>