diff --git a/Dockerfile b/Dockerfile index bcc372f..310ad29 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,9 +10,14 @@ ARG UID RUN if [ -z "${UID}" ] ; then echo UID argument is NOT provided ; else usermod --non-unique --uid 1000 www-data ; fi # enable mod_rewrite for laravel routing to work (.htaccess) -RUN a2enmod rewrite -RUN apt-get update && apt-get install -y git zip unzip +RUN a2enmod rewrite \ + && apt-get update \ + && apt-get install --assume-yes --no-install-recommends --quiet \ + git zip unzip build-essential libmagickwand-dev \ + && apt-get clean all \ + && pecl install imagick \ + && docker-php-ext-enable imagick COPY . /var/www/html COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer diff --git a/app/Services/Image/ImageService.php b/app/Services/Image/ImageService.php index f9148c2..fea2842 100644 --- a/app/Services/Image/ImageService.php +++ b/app/Services/Image/ImageService.php @@ -17,12 +17,27 @@ class ImageService $imageData = base64_decode($base64ImageData); $ext = explode('/', $mimeType)[1]; - Storage::put('public/images/' . $imageId . '.' . $ext , $imageData); - $relativePath = Storage::url('public/images/' . $imageId . '.png'); + $imagePath = 'public/images/' . $imageId . '.' . $ext; + Storage::put($imagePath , $imageData); + $relativeUrl = Storage::url($imagePath); + $filesystemPath = Storage::path($imagePath); + + $resolution = []; + try { + $image = new \Imagick($filesystemPath); + $resolution = $image->getImageGeometry(); + } catch (\ImagickException $e) { + //do nothing + } + // resize to thumbnail +// $image->thumbnailImage(200, 200); +// $thumbPath = 'public/images/' . $imageId . '-thumb.' . $ext; +// Storage::put($thumbPath , $image->getImageBlob()); return [ - 'url' => asset($relativePath), + 'url' => asset($relativeUrl), 'id' => $imageId, + ...$resolution, // todo - size, width, height, thumb, etc ]; } diff --git a/composer.json b/composer.json index d7a1dba..7cdbd02 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "laravel/framework": "^10.10", "laravel/sanctum": "^3.3", "laravel/tinker": "^2.8", - "ext-curl": "*" + "ext-curl": "*", + "ext-imagick": "*" }, "require-dev": { "fakerphp/faker": "^1.9.1",