PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/storecommander/ead6f6fce09/SC/lib/js/ckeditor/kcfinder/lib/class_image.php

https://gitlab.com/ptisky/API_prestashop
PHP | 264 lines | 77 code | 50 blank | 137 comment | 8 complexity | dbec8cb9c74afb6f56c37159c8a84a16 MD5 | raw file
  1. <?php
  2. /**
  3. * Store Commander
  4. *
  5. * @category administration
  6. * @author Store Commander - support@storecommander.com
  7. * @version 2015-09-15
  8. * @uses Prestashop modules
  9. * @since 2009
  10. * @copyright Copyright &copy; 2009-2015, Store Commander
  11. * @license commercial
  12. * All rights reserved! Copying, duplication strictly prohibited
  13. *
  14. * *****************************************
  15. * * STORE COMMANDER *
  16. * * http://www.StoreCommander.com *
  17. * * V 2015-09-15 *
  18. * *****************************************
  19. *
  20. * Compatibility: PS version: 1.1 to 1.6.1
  21. *
  22. **/
  23. /** This file is part of KCFinder project
  24. *
  25. * @desc Abstract image driver class
  26. * @package KCFinder
  27. * @version 3.12
  28. * @author Pavel Tzonkov <sunhater@sunhater.com>
  29. * @copyright 2010-2014 KCFinder Project
  30. * @license http://opensource.org/licenses/GPL-3.0 GPLv3
  31. * @license http://opensource.org/licenses/LGPL-3.0 LGPLv3
  32. * @link http://kcfinder.sunhater.com
  33. */
  34. namespace kcfinder;
  35. abstract class image {
  36. const DEFAULT_JPEG_QUALITY = 75;
  37. /** Image resource or object
  38. * @var mixed */
  39. protected $image;
  40. /** Image width in pixels
  41. * @var integer */
  42. protected $width;
  43. /** Image height in pixels
  44. * @var integer */
  45. protected $height;
  46. /** Init error
  47. * @var bool */
  48. protected $initError = false;
  49. /** Driver specific options
  50. * @var array */
  51. protected $options = array();
  52. /** Magic method which allows read-only access to all protected or private
  53. * class properties
  54. * @param string $property
  55. * @return mixed */
  56. final public function __get($property) {
  57. return property_exists($this, $property) ? $this->$property : null;
  58. }
  59. /** Constructor. Parameter $image should be:
  60. * 1. An instance of image driver class (copy instance).
  61. * 2. An image represented by the type of the $image property
  62. * (resource or object).
  63. * 3. An array with two elements. First - width, second - height.
  64. * Creates a blank image.
  65. * 4. A filename string. Get image form file.
  66. * Second paramaeter is used by pass some specific image driver options
  67. * @param mixed $image
  68. * @param array $options */
  69. public function __construct($image, array $options=array()) {
  70. $this->image = $this->width = $this->height = null;
  71. $imageDetails = $this->buildImage($image);
  72. if ($imageDetails !== false)
  73. list($this->image, $this->width, $this->height) = $imageDetails;
  74. else
  75. $this->initError = true;
  76. $this->options = $options;
  77. }
  78. /** Factory pattern to load selected driver. $image and $options are passed
  79. * to the constructor of the image driver
  80. * @param string $driver
  81. * @param mixed $image
  82. * @return object */
  83. final static function factory($driver, $image, array $options=array()) {
  84. $class = __NAMESPACE__ . "\\image_$driver";
  85. return new $class($image, $options);
  86. }
  87. /** Checks if the drivers in the array parameter could be used. Returns first
  88. * found one
  89. * @param array $drivers
  90. * @return string */
  91. final static function getDriver(array $drivers=array('gd')) {
  92. foreach ($drivers as $driver) {
  93. if (!preg_match('/^[a-z0-9\_]+$/i', $driver))
  94. continue;
  95. $class = __NAMESPACE__ . "\\image_$driver";
  96. if (class_exists($class) && method_exists($class, "available")) {
  97. eval("\$avail = $class::available();");
  98. if ($avail) return $driver;
  99. }
  100. }
  101. return false;
  102. }
  103. /** Returns an array. Element 0 - image resource. Element 1 - width. Element 2 - height.
  104. * Returns FALSE on failure.
  105. * @param mixed $image
  106. * @return array */
  107. final protected function buildImage($image) {
  108. $class = get_class($this);
  109. if ($image instanceof $class) {
  110. $width = $image->width;
  111. $height = $image->height;
  112. $img = $image->image;
  113. } elseif (is_array($image)) {
  114. list($key, $width) = each($image);
  115. list($key, $height) = each($image);
  116. $img = $this->getBlankImage($width, $height);
  117. } else
  118. $img = $this->getImage($image, $width, $height);
  119. return ($img !== false)
  120. ? array($img, $width, $height)
  121. : false;
  122. }
  123. /** Returns calculated proportional width from the given height
  124. * @param integer $resizedHeight
  125. * @return integer */
  126. final public function getPropWidth($resizedHeight) {
  127. $width = round(($this->width * $resizedHeight) / $this->height);
  128. if (!$width) $width = 1;
  129. return $width;
  130. }
  131. /** Returns calculated proportional height from the given width
  132. * @param integer $resizedWidth
  133. * @return integer */
  134. final public function getPropHeight($resizedWidth) {
  135. $height = round(($this->height * $resizedWidth) / $this->width);
  136. if (!$height) $height = 1;
  137. return $height;
  138. }
  139. /** Checks if PHP needs some extra extensions to use the image driver. This
  140. * static method should be implemented into driver classes like abstract
  141. * methods
  142. * @return bool */
  143. static function available() { return false; }
  144. /** Checks if file is an image. This static method should be implemented into
  145. * driver classes like abstract methods
  146. * @param string $file
  147. * @return bool */
  148. static function checkImage($file) { return false; }
  149. /** Resize image. Should return TRUE on success or FALSE on failure
  150. * @param integer $width
  151. * @param integer $height
  152. * @return bool */
  153. abstract public function resize($width, $height);
  154. /** Resize image to fit in given resolution. Should returns TRUE on success
  155. * or FALSE on failure. If $background is set, the image size will be
  156. * $width x $height and the empty spaces (if any) will be filled with defined
  157. * color. Background color examples: "#5f5", "#ff67ca", array(255, 255, 255)
  158. * @param integer $width
  159. * @param integer $height
  160. * @param mixed $background
  161. * @return bool */
  162. abstract public function resizeFit($width, $height, $background=false);
  163. /** Resize and crop the image to fit in given resolution. Returns TRUE on
  164. * success or FALSE on failure
  165. * @param mixed $src
  166. * @param integer $offset
  167. * @return bool */
  168. abstract public function resizeCrop($width, $height, $offset=false);
  169. /** Rotate image
  170. * @param integer $angle
  171. * @param string $background
  172. * @return bool */
  173. abstract public function rotate($angle, $background="#000000");
  174. abstract public function flipHorizontal();
  175. abstract public function flipVertical();
  176. /** Apply a PNG or GIF watermark to the image. $top and $left parameters sets
  177. * the offset of the watermark in pixels. Boolean and NULL values are possible
  178. * too. In default case (FALSE, FALSE) the watermark should be applyed to
  179. * the bottom right corner. NULL values means center aligning. If the
  180. * watermark is bigger than the image or it's partialy or fully outside the
  181. * image, it shoudn't be applied
  182. * @param string $file
  183. * @param mixed $top
  184. * @param mixed $left
  185. * @return bool */
  186. abstract public function watermark($file, $left=false, $top=false);
  187. /** Should output the image. Second parameter is used to pass some options like
  188. * 'file' - if is set, the output will be written to a file
  189. * 'quality' - compression quality
  190. * It's possible to use extra specific options required by image type ($type)
  191. * @param string $type
  192. * @param array $options
  193. * @return bool */
  194. abstract public function output($type='jpeg', array $options=array());
  195. /** This method should create a blank image with selected size. Should returns
  196. * resource or object related to the created image, which will be passed to
  197. * $image property
  198. * @param integer $width
  199. * @param integer $height
  200. * @return mixed */
  201. abstract protected function getBlankImage($width, $height);
  202. /** This method should create an image from source image. Only first parameter
  203. * ($image) is input. Its type should be filename string or a type of the
  204. * $image property. See the constructor reference for details. The
  205. * parametters $width and $height are output only. Should returns resource or
  206. * object related to the created image, which will be passed to $image
  207. * property
  208. * @param mixed $image
  209. * @param integer $width
  210. * @param integer $height
  211. * @return mixed */
  212. abstract protected function getImage($image, &$width, &$height);
  213. }
  214. ?>