summaryrefslogtreecommitdiff
path: root/src/images.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/images.php')
-rw-r--r--src/images.php12
1 files changed, 11 insertions, 1 deletions
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");
}