summaryrefslogtreecommitdiff
path: root/src/images.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-12-08 22:17:05 +0500
committerilotterytea <iltsu@alright.party>2025-12-08 22:17:05 +0500
commit95800ffe216a83bc0eba994ecc53ed22860fe90e (patch)
tree69f1bcb85e63a5fc0fcbc6d70eb56e22940fd6fd /src/images.php
parent57472eab3c7b035392c6a5aa240593ecaa7d1ccf (diff)
upd: include paths
Diffstat (limited to 'src/images.php')
-rw-r--r--src/images.php78
1 files changed, 0 insertions, 78 deletions
diff --git a/src/images.php b/src/images.php
deleted file mode 100644
index 9ec0301..0000000
--- a/src/images.php
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-function resize_image(string $src_path, string $dst_path, int $max_width, int $max_height, bool $set_format = true, bool $stretch = false): int|null
-{
- if ($src_path == "") {
- return -2;
- }
-
- $image = getimagesize($src_path);
-
- if ($image == false) {
- return -1;
- }
-
- $format = $set_format ? ".webp" : "";
-
- $width = $image[0];
- $height = $image[1];
- $ratio = min($max_width / $width, $max_height / $height);
- $new_width = $stretch ? $max_width : (int) ($width * $ratio);
- $new_height = $stretch ? $max_height : (int) ($height * $ratio);
-
- $input_path = escapeshellarg($src_path);
- $output_path = escapeshellarg("$dst_path$format");
-
- $result_code = null;
-
- exec(command: "magick convert $input_path -coalesce -resize {$new_width}x{$new_height}! -loop 0 $output_path", result_code: $result_code);
-
- return $result_code;
-}
-
-function create_image_bundle(string $src_path, string $dst_path, int $max_width, int $max_height, bool $set_format = true, bool $stretch = false): int|null
-{
- if (!is_dir($dst_path)) {
- if (!mkdir($dst_path, 0777, true)) {
- return -3;
- }
- }
-
- if ($err = resize_image($src_path, "$dst_path/3x", $max_width, $max_height, $set_format, $stretch)) {
- array_map("unlink", glob("$dst_path/*.*"));
- rmdir($dst_path);
- return $err;
- }
-
- if ($err = resize_image($src_path, "$dst_path/2x", round($max_width / 2), round($max_height / 2), $set_format, $stretch)) {
- array_map("unlink", glob("$dst_path/*.*"));
- rmdir($dst_path);
- return $err;
- }
-
- if ($err = resize_image($src_path, "$dst_path/1x", round($max_width / 4), round($max_height / 4), $set_format, $stretch)) {
- array_map("unlink", glob("$dst_path/*.*"));
- rmdir($dst_path);
- return $err;
- }
-
- return null;
-}
-
-function get_file_extension(string $path): string|null
-{
- if ($file = getimagesize($path)) {
- return image_type_to_extension(intval($file[2]), false);
- }
-
- return null;
-}
-
-function does_file_meet_requirements(string $path, int $max_width, int $max_height): array
-{
- $file = getimagesize($path);
- if (!$file) {
- return [false, null];
- }
-
- return [$file[0] <= $max_width && $file[1] <= $max_height, image_type_to_extension(intval($file[2]), false)];
-} \ No newline at end of file