X-Git-Url: https://git.rapsys.eu/packbundle/blobdiff_plain/60451adddba856f93d2b4a03dab2e7887fa8f6d0..4b8ba7387936a2385a323d341847fa050c7846de:/Util/ImageUtil.php diff --git a/Util/ImageUtil.php b/Util/ImageUtil.php index d1b15cb..871b99a 100644 --- a/Util/ImageUtil.php +++ b/Util/ImageUtil.php @@ -16,43 +16,43 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Routing\RouterInterface; /** - * Helps manage map + * Manages image */ class ImageUtil { /** * The captcha width */ - const captchaWidth = 192; + const width = 192; /** * The captcha height */ - const captchaHeight = 52; + const height = 52; /** * The captcha background color */ - const captchaBackground = 'white'; + const background = 'white'; /** * The captcha fill color */ - const captchaFill = '#cff'; + const fill = '#cff'; /** * The captcha font size */ - const captchaFontSize = 45; + const fontSize = 45; /** * The captcha stroke color */ - const captchaStroke = '#00c3f9'; + const stroke = '#00c3f9'; /** * The captcha stroke width */ - const captchaStrokeWidth = 2; + const strokeWidth = 2; /** * The thumb width @@ -65,58 +65,15 @@ class ImageUtil { const thumbHeight = 640; /** - * The cache path - */ - protected string $cache; - - /** - * The public path - */ - protected string $public; - - /** - * The RouterInterface instance - */ - protected RouterInterface $router; - - /** - * The SluggerUtil instance - */ - protected SluggerUtil $slugger; - - /** - * Creates a new map util + * Creates a new image util * * @param RouterInterface $router The RouterInterface instance * @param SluggerUtil $slugger The SluggerUtil instance + * @param string $cache The cache directory + * @param string $path The public path + * @param string $prefix The prefix */ - function __construct(RouterInterface $router, SluggerUtil $slugger, string $cache = '../var/cache/image', string $public = './bundles/rapsyspack/image', $captchaBackground = self::captchaBackground, $captchaFill = self::captchaFill, $captchaFontSize = self::captchaFontSize, $captchaStroke = self::captchaStroke, $captchaStrokeWidth = self::captchaStrokeWidth) { - //Set cache - $this->cache = $cache; - - //set captcha background - $this->captchaBackground = $captchaBackground; - - //set captcha fill - $this->captchaFill = $captchaFill; - - //set captcha font size - $this->captchaFontSize = $captchaFontSize; - - //set captcha stroke - $this->captchaStroke = $captchaStroke; - - //set captcha stroke width - $this->captchaStrokeWidth = $captchaStrokeWidth; - - //Set public - $this->public = $public; - - //Set router - $this->router = $router; - - //Set slugger - $this->slugger = $slugger; + function __construct(protected RouterInterface $router, protected SluggerUtil $slugger, protected string $cache = '../var/cache', protected string $path = './bundles/rapsyspack', protected string $prefix = 'image', protected string $background = self::background, protected string $fill = self::fill, protected int $fontSize = self::fontSize, protected string $stroke = self::stroke, protected int $strokeWidth = self::strokeWidth) { } /** @@ -127,7 +84,7 @@ class ImageUtil { * @param int $height The height * @return array The captcha data */ - public function getCaptcha(int $updated, int $width = self::captchaWidth, int $height = self::captchaHeight): array { + public function getCaptcha(int $updated, int $width = self::width, int $height = self::height): array { //Set a $a = rand(0, 9); @@ -151,7 +108,7 @@ class ImageUtil { 'token' => $this->slugger->hash(strval($a * $b + $c)), 'value' => strval($a * $b + $c), 'equation' => str_replace([' ', '*', '+'], ['-', 'mul', 'add'], $equation), - 'src' => $this->router->generate('rapsys_pack_captcha', ['hash' => $hash, 'updated' => $updated, 'equation' => $short, 'width' => $width, 'height' => $height]), + 'src' => $this->router->generate('rapsyspack_captcha', ['hash' => $hash, 'updated' => $updated, 'equation' => $short, 'width' => $width, 'height' => $height]), 'width' => $width, 'height' => $height ]; @@ -183,13 +140,48 @@ class ImageUtil { //Return array return [ 'caption' => $caption, - 'link' => $this->router->generate('rapsys_pack_thumb', ['hash' => $link, 'updated' => $updated, 'path' => $short, 'width' => $imageWidth, 'height' => $imageHeight]), - 'src' => $this->router->generate('rapsys_pack_thumb', ['hash' => $src, 'updated' => $updated, 'path' => $short, 'width' => $width, 'height' => $height]), + 'link' => $this->router->generate('rapsyspack_thumb', ['hash' => $link, 'updated' => $updated, 'path' => $short, 'width' => $imageWidth, 'height' => $imageHeight]), + 'src' => $this->router->generate('rapsyspack_thumb', ['hash' => $src, 'updated' => $updated, 'path' => $short, 'width' => $width, 'height' => $height]), 'width' => $width, 'height' => $height ]; } + /** + * Get captcha background color + */ + public function getBackground() { + return $this->background; + } + + /** + * Get captcha fill color + */ + public function getFill() { + return $this->fill; + } + + /** + * Get captcha font size + */ + public function getFontSize() { + return $this->fontSize; + } + + /** + * Get captcha stroke color + */ + public function getStroke() { + return $this->stroke; + } + + /** + * Get captcha stroke width + */ + public function getStrokeWidth() { + return $this->strokeWidth; + } + /** * Remove image * @@ -202,7 +194,7 @@ class ImageUtil { $hash = array_reverse(str_split(strval($updated))); //Set dir - $dir = $this->public.'/'.$hash[0].'/'.$hash[1].'/'.$hash[2].'/'.$updated.'/'.$this->slugger->short($path); + $dir = $this->path.'/'.$this->prefix.'/'.$hash[0].'/'.$hash[1].'/'.$hash[2].'/'.$updated.'/'.$this->slugger->short($path); //Set removes $removes = [];