summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-29 02:06:11 +0500
committerilotterytea <iltsu@alright.party>2025-04-29 02:06:11 +0500
commit93c02436fb0b7afffb6c62547385757b1a1b57f8 (patch)
treeb60ccd0a1df6076f97c3898d952ec3262dff34d7 /src
parentc95dfa9e3dd18c0835626ec29b814cc2b11b7fae (diff)
feat: download user's profile banner
Diffstat (limited to 'src')
-rw-r--r--src/config.php3
-rw-r--r--src/images.php12
2 files changed, 13 insertions, 2 deletions
diff --git a/src/config.php b/src/config.php
index 9191bb9..7c740d1 100644
--- a/src/config.php
+++ b/src/config.php
@@ -17,4 +17,5 @@ define("ANONYMOUS_DEFAULT_NAME", "chud");
// ACCOUNTS
define("ACCOUNT_USERNAME_REGEX", "/^[A-Za-z0-9_]+$/");
define("ACCOUNT_USERNAME_MAX_LENGTH", 20);
-define("ACCOUNT_PFP_MAX_SIZE", [128, 128]); \ No newline at end of file
+define("ACCOUNT_PFP_MAX_SIZE", [128, 128]);
+define("ACCOUNT_BANNER_MAX_SIZE", [1920, 1080]); \ No newline at end of file
diff --git a/src/images.php b/src/images.php
index 970fa99..d57794f 100644
--- a/src/images.php
+++ b/src/images.php
@@ -1,5 +1,5 @@
<?php
-function resize_image(string $src_path, string $dst_path, int $max_width, int $max_height, bool $set_format = true): string|null
+function resize_image(string $src_path, string $dst_path, int $max_width, int $max_height, bool $set_format = true, bool $stretch = false): string|null
{
if ($src_path == "" || !getimagesize($src_path)) {
return json_encode([
@@ -28,6 +28,11 @@ function resize_image(string $src_path, string $dst_path, int $max_width, int $m
$new_width = (int) ($width * $ratio);
$new_height = (int) ($height * $ratio);
+ if ($stretch) {
+ $new_width = $max_width;
+ $new_height = $max_height;
+ }
+
$frame->resizeImage($new_width, $new_height, Imagick::FILTER_TRIANGLE, 1);
$frame->setImagePage($new_width, $new_height, 0, 0);
}
@@ -41,6 +46,11 @@ function resize_image(string $src_path, string $dst_path, int $max_width, int $m
$new_width = (int) ($width * $ratio);
$new_height = (int) ($height * $ratio);
+ if ($stretch) {
+ $new_width = $max_width;
+ $new_height = $max_height;
+ }
+
$imagick->resizeImage($new_width, $new_height, Imagick::FILTER_TRIANGLE, 1);
$imagick->writeImage("$dst_path$format");
}