From 9c2f42e423096bdf56b7f96e07221f6420b0e337 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 19 Apr 2025 16:47:23 +0500 Subject: feat: upload emotes --- src/images.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/images.php (limited to 'src/images.php') diff --git a/src/images.php b/src/images.php new file mode 100644 index 0000000..0e09814 --- /dev/null +++ b/src/images.php @@ -0,0 +1,48 @@ + 400, + "message" => "Not an image", + "data" => null + ]); + } + + $imagick = new Imagick(); + + $imagick->readImage($src_path); + $format = strtolower($imagick->getImageFormat()); + + if ($imagick->getNumberImages() > 1) { + $imagick = $imagick->coalesceImages(); + + foreach ($imagick as $frame) { + $width = $frame->getImageWidth(); + $height = $frame->getImageHeight(); + $ratio = min($max_width / $width, $max_height / $height); + $new_width = (int) ($width * $ratio); + $new_height = (int) ($height * $ratio); + + $frame->resizeImage($new_width, $new_height, Imagick::FILTER_TRIANGLE, 1); + $frame->setImagePage($new_width, $new_height, 0, 0); + } + + $imagick = $imagick->deconstructImages(); + $imagick->writeImages("$dst_path.$format", true); + } else { + $width = $imagick->getImageWidth(); + $height = $imagick->getImageHeight(); + $ratio = min($max_width / $width, $max_height / $height); + $new_width = (int) ($width * $ratio); + $new_height = (int) ($height * $ratio); + + $imagick->resizeImage($new_width, $new_height, Imagick::FILTER_TRIANGLE, 1); + $imagick->writeImage("$dst_path.$format"); + } + + $imagick->clear(); + $imagick->destroy(); + + return null; +} \ No newline at end of file -- cgit v1.2.3