From 7a66de9852d4683a7b5cdcedb8e88cfdc73f4b56 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 19 Apr 2025 17:27:12 +0500 Subject: feat: extract extension and mime from image --- src/images.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/images.php') diff --git a/src/images.php b/src/images.php index 0e09814..fea1825 100644 --- a/src/images.php +++ b/src/images.php @@ -45,4 +45,22 @@ function resize_image(string $src_path, string $dst_path, int $max_width, int $m $imagick->destroy(); return null; +} + +function get_mime_and_ext(string $src_path): array|null +{ + if ($src_path == "") { + return null; + } + + $imagick = new Imagick(); + + $imagick->readImage($src_path); + $ext = strtolower($imagick->getImageFormat()); + $mime = $imagick->getImageMimeType(); + + $imagick->clear(); + $imagick->destroy(); + + return [$mime, $ext]; } \ No newline at end of file -- cgit v1.2.3