diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 4526e23..20bcc7c 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -33,3 +33,4 @@ security: access_control: - { path: ^/admin, roles: ROLE_ADMIN } - { path: ^/follow_plugin, roles: ROLE_USER } + - { path: ^/gif_modify, roles: ROLE_USER } diff --git a/public/img/PHP.png b/public/img/PHP.png new file mode 100644 index 0000000..59420f7 Binary files /dev/null and b/public/img/PHP.png differ diff --git a/public/img/circle_php.png b/public/img/circle_php.png new file mode 100644 index 0000000..dd47366 Binary files /dev/null and b/public/img/circle_php.png differ diff --git a/public/img/original.gif b/public/img/original.gif new file mode 100644 index 0000000..50e3381 Binary files /dev/null and b/public/img/original.gif differ diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index 629c27a..b383ec8 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -4,6 +4,7 @@ namespace App\Controller; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use App\Utils\GifModifier; class IndexController extends AbstractController { @@ -22,4 +23,47 @@ class IndexController extends AbstractController { return $this->render('follow.html.twig'); } + + /** + * @Route("/gif_modify", name="gif_page", methods={"GET"}) + */ + public function gifModify() + { + return $this->render('gif_modify.html.twig', [ + 'result' => false, + ]); + } + + /** + * @Route("/gif_modify/process", name="gif_process_page", methods={"GET"}) + */ + public function gifModifyProcess() + { + $img_dir = dirname(dirname(__DIR__)).'/public/img/'; + $gifModify = new GifModifier(); + $gifModify->modify($img_dir.'original.gif', 180, 146, $img_dir.'PHP.png', 36, 52, $img_dir.'out_180_146.gif'); + $gifModify->modify($img_dir.'original.gif', 300, 243, $img_dir.'circle_php.png', 88, 152, $img_dir.'out_300_243.gif'); + + return $this->redirectToRoute('gif_result_page'); + } + + /** + * @Route("/gif_modify/results", name="gif_result_page", methods={"GET"}) + */ + public function gifModifyResults() + { + return $this->render('gif_modify.html.twig', [ + 'result' => true, + 'images' => [ + [ + 'x' => 180, + 'y' => 146, + ], + [ + 'x' => 300, + 'y' => 243, + ], + ], + ]); + } } diff --git a/src/Utils/GifModifier.php b/src/Utils/GifModifier.php new file mode 100644 index 0000000..5c9d95e --- /dev/null +++ b/src/Utils/GifModifier.php @@ -0,0 +1,54 @@ +readImage($watermarkFilename); + + $gifFile = new Imagick($filename); + + $fileFormat = $gifFile->getImageFormat(); + + if ('GIF' == $fileFormat) { + $frames = $gifFile->coalesceImages(); + + foreach ($frames as $frame) { + $frame->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1); + $frame->compositeImage($watermark, Imagick::COMPOSITE_OVER, $watermarkX, $watermarkY); + } + + $out_file = $frames->deconstructImages(); + $out_file->writeImages($outFilename, true); + + $out_file->clear(); + } + + $gifFile->clear(); + $watermark->clear(); + } +} diff --git a/templates/gif_modify.html.twig b/templates/gif_modify.html.twig new file mode 100644 index 0000000..1fff284 --- /dev/null +++ b/templates/gif_modify.html.twig @@ -0,0 +1,27 @@ +{% extends "base.html.twig" %} +{% block title %} + Ресайз и наложение ватермарки{% if result == true %} (Результат){% endif %}. +{% endblock %} +{% block body %} +
+ {% if result == false %} + ← Главная +
+ Изменить gif + {% else %} + ← Страница изменения gif +
+
original.gif
+ +
circle_php.png
+ +
PHP.png
+ + {% for image in images %} +
+
out_{{ image.x }}_{{ image.y }}.gif
+ + {% endfor %} + {% endif %} +
+{% endblock %} \ No newline at end of file diff --git a/templates/index.html.twig b/templates/index.html.twig index 06ef3a5..dac48b0 100644 --- a/templates/index.html.twig +++ b/templates/index.html.twig @@ -11,7 +11,12 @@ {% endif %}
{% if is_granted('ROLE_USER') %} - Плагин follow + Плагин follow +
+ Результат изменения gif +
+ Страница изменения gif +
{% endif %} {% if is_granted('ROLE_ADMIN') %} Список пользователей