summaryrefslogtreecommitdiff
path: root/src/images.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-27 22:24:05 +0500
committerilotterytea <iltsu@alright.party>2025-04-27 22:24:05 +0500
commit067348835299febed3080ab61ffca365cd07743f (patch)
tree5abe32ea3837e425612f3b6d939ee06f7baff438 /src/images.php
parent69355b508f0fd012b08c773b950e7b0be96c9185 (diff)
feat: change username and pfp
Diffstat (limited to 'src/images.php')
-rw-r--r--src/images.php12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/images.php b/src/images.php
index fea1825..970fa99 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): string|null
+function resize_image(string $src_path, string $dst_path, int $max_width, int $max_height, bool $set_format = true): string|null
{
if ($src_path == "" || !getimagesize($src_path)) {
return json_encode([
@@ -12,7 +12,11 @@ function resize_image(string $src_path, string $dst_path, int $max_width, int $m
$imagick = new Imagick();
$imagick->readImage($src_path);
- $format = strtolower($imagick->getImageFormat());
+ $format = "." . strtolower($imagick->getImageFormat());
+
+ if (!$set_format) {
+ $format = "";
+ }
if ($imagick->getNumberImages() > 1) {
$imagick = $imagick->coalesceImages();
@@ -29,7 +33,7 @@ function resize_image(string $src_path, string $dst_path, int $max_width, int $m
}
$imagick = $imagick->deconstructImages();
- $imagick->writeImages("$dst_path.$format", true);
+ $imagick->writeImages("$dst_path$format", true);
} else {
$width = $imagick->getImageWidth();
$height = $imagick->getImageHeight();
@@ -38,7 +42,7 @@ function resize_image(string $src_path, string $dst_path, int $max_width, int $m
$new_height = (int) ($height * $ratio);
$imagick->resizeImage($new_width, $new_height, Imagick::FILTER_TRIANGLE, 1);
- $imagick->writeImage("$dst_path.$format");
+ $imagick->writeImage("$dst_path$format");
}
$imagick->clear();