diff --git a/composer.json b/composer.json index 05614be..2969a7f 100755 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "ext-json": "*", "ext-pdo": "*", "imagine/imagine": "^1.3", - "intervention/image": "^2.7", + "intervention/image": "^3.1.0", "ksubileau/color-thief-php": "^2.0", "laravel/framework": "^10.4.1", "php-ffmpeg/php-ffmpeg": "^1.1", diff --git a/docs/README.md b/docs/README.md index 21b8337..8148dc2 100755 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ # Introduction -[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/mostafaznv/larupload/run-tests.yml?branch=master\&label=Build\&style=flat-square\&logo=github)](https://github.com/mostafaznv/larupload/actions) [![Codecov branch](https://img.shields.io/codecov/c/github/mostafaznv/larupload/master.svg?style=flat-square\&logo=codecov)](https://app.codecov.io/gh/mostafaznv/larupload) [![Quality Score](https://img.shields.io/scrutinizer/g/mostafaznv/larupload.svg?style=flat-square)](https://scrutinizer-ci.com/g/mostafaznv/larupload) ![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square) [![Latest Version on Packagist](https://img.shields.io/packagist/v/mostafaznv/larupload.svg?style=flat-square)](https://packagist.org/packages/mostafaznv/larupload) [![Total Downloads](https://img.shields.io/packagist/dt/mostafaznv/larupload.svg?style=flat-square)](https://packagist.org/packages/mostafaznv/larupload) +[GitHub Workflow Status](https://github.com/mostafaznv/larupload/actions) [Codecov branch](https://app.codecov.io/gh/mostafaznv/larupload) [Quality Score](https://scrutinizer-ci.com/g/mostafaznv/larupload) Software License [Latest Version on Packagist](https://packagist.org/packages/mostafaznv/larupload) [Total Downloads](https://packagist.org/packages/mostafaznv/larupload) @@ -14,7 +14,11 @@ It offers many useful features, including the ability to resize, crop, and optim Moreover, Larupload can calculate the dominant colors of videos and images, as well as extract their width, height, and duration for videos and audio files -[![Donate](https://mostafaznv.github.io/donate/donate.svg)](getting-started/support-us.md) +
+ +
+ +
diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index f885680..1c9956b 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -7,7 +7,6 @@ * [Laravel Nova integration](getting-started/laravel-nova-integration.md) * [Support Us](getting-started/support-us.md) * [License](getting-started/license.md) -* [Laravel Nova Integration](getting-started/laravel-nova-integration-1.md) ## 🚀 Basic Usage diff --git a/docs/advanced-usage/attachment/media-styles.md b/docs/advanced-usage/attachment/media-styles.md index e08cdb6..4ffaf26 100644 --- a/docs/advanced-usage/attachment/media-styles.md +++ b/docs/advanced-usage/attachment/media-styles.md @@ -14,7 +14,7 @@ On the other hand, if you want to manipulate images or videos, you should use th ### Image Style -
IndexNameTypeRequiredDefaultDescription
1namestringtrue–style name. examples: thumbnail, small, ...
2width?intfalsenullwidth of the manipulated image
3height?intfalsenullheight of the manipulated image
4modeLaruploadMediaStylefalseAUTOthis argument specifies how Larupload should manipulate the uploaded image and can take on any of the following values: FIT, AUTO, SCALE_WIDTH, SCALE_HEIGHT, CROP
+
IndexNameTypeRequiredDefaultDescription
1namestringtrue–style name. examples: thumbnail, small, ...
2width?intfalsenullwidth of the manipulated image
3height?intfalsenullheight of the manipulated image
4modeLaruploadMediaStylefalseAUTOthis argument specifies how Larupload should manipulate the uploaded image and can take on any of the following values: FIT, AUTO, SCALE_WIDTH, SCALE_HEIGHT, CROP
```php IndexNameTypeRequiredDefaultDescription1namestringtrue–style name. examples: thumbnail, small, ...2width?intfalsenullwidth of the manipulated video3height?intfalsenullheight of the manipulated video4modeLaruploadMediaStylefalseSCALE_HEIGHTthis argument specifies how Larupload should manipulate the uploaded video and can take on any of the following values: FIT, AUTO, SCALE_WIDTH, SCALE_HEIGHT, CROP5formatX264falsenew X264by default, the encoding format for video is X264. However, users can specify additional options for this format, including adjusting the kilobitrate for both audio and video. This allows for more precise configuration and optimization of the user's encoding preferences.6paddingboolfalsefalseIf set to true, padding will be applied to the video using a black color in order to fit the given dimensions. +
IndexNameTypeRequiredDefaultDescription
1namestringtrue–style name. examples: thumbnail, small, ...
2width?intfalsenullwidth of the manipulated video
3height?intfalsenullheight of the manipulated video
4modeLaruploadMediaStylefalseSCALE_HEIGHTthis argument specifies how Larupload should manipulate the uploaded video and can take on any of the following values: FIT, AUTO, SCALE_WIDTH, SCALE_HEIGHT, CROP
5formatX264falsenew X264by default, the encoding format for video is X264. However, users can specify additional options for this format, including adjusting the kilobitrate for both audio and video. This allows for more precise configuration and optimization of the user's encoding preferences.
6paddingboolfalsefalseIf set to true, padding will be applied to the video using a black color in order to fit the given dimensions.
```php IndexNameTypeRequiredDefaultDescription1namestringtrue–label for stream quality. highly recommended to use string labels like 720p2widthinttrue–3heightinttrue–4formatX264true–by default, the encoding format for video is X264. However, users can specify additional options for this format, including adjusting the kilobitrate for both audio and video. This allows for more precise configuration and optimization of the user's encoding preferences.5paddingboolfalsefalseIf set to true, padding will be applied to the video using a black color in order to fit the given dimensions. +
IndexNameTypeRequiredDefaultDescription
1namestringtrue–label for stream quality. highly recommended to use string labels like 720p
2widthinttrue–
3heightinttrue–
4formatX264true–by default, the encoding format for video is X264. However, users can specify additional options for this format, including adjusting the kilobitrate for both audio and video. This allows for more precise configuration and optimization of the user's encoding preferences.
5paddingboolfalsefalseIf set to true, padding will be applied to the video using a black color in order to fit the given dimensions.
```php + +
+ + diff --git a/src/Storage/Image.php b/src/Storage/Image.php index 771e8df..f8fcc13 100755 --- a/src/Storage/Image.php +++ b/src/Storage/Image.php @@ -5,7 +5,7 @@ use ColorThief\ColorThief; use Exception; use Illuminate\Http\UploadedFile; -use Intervention\Image\Image as InterventionImage; +use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\ImageManager; use JetBrains\PhpStorm\ArrayShape; use Mostafaznv\Larupload\DTOs\Style\ImageStyle; @@ -19,7 +19,7 @@ class Image { protected readonly UploadedFile $file; - protected readonly InterventionImage $image; + protected readonly ImageInterface $image; protected readonly string $disk; @@ -37,11 +37,12 @@ public function __construct(UploadedFile $file, string $disk, LaruploadImageLibr $path = $file->getRealPath(); - $imageManager = new ImageManager([ - 'driver' => $library === LaruploadImageLibrary::GD ? 'gd' : 'imagick', - ]); + $imageManager = $library === LaruploadImageLibrary::GD + ? ImageManager::gd() + : ImageManager::imagick(); - $this->image = $imageManager->make($path); + + $this->image = $imageManager->read($path); } @@ -76,7 +77,7 @@ public function resize(string $saveTo, ImageStyle $style): bool if ($this->driverIsLocal) { - $this->image->save($saveTo); + $this->save($saveTo); } else { list($path, $name) = split_larupload_path($saveTo); @@ -85,7 +86,7 @@ public function resize(string $saveTo, ImageStyle $style): bool $tempName = time() . '-' . $name; $temp = "$tempDir/$tempName"; - $this->image->save($temp); + $this->save($temp); Storage::disk($this->disk)->putFileAs($path, new File($temp), $name); @@ -189,9 +190,7 @@ private function resizeAuto(int $width = null, int $height = null): void */ private function resizeCrop(int $width, int $height): void { - $this->image->fit($width, $height, function($constraint) { - $constraint->upsize(); - }); + $this->image->cover($width, $height); } /** @@ -200,9 +199,9 @@ private function resizeCrop(int $width, int $height): void */ private function resizeLandscape(int $width): void { - $this->image->widen($width, function($constraint) { - $constraint->upsize(); - }); + $this->image->scale( + width: $width + ); } /** @@ -211,9 +210,9 @@ private function resizeLandscape(int $width): void */ private function resizePortrait(int $height): void { - $this->image->heighten($height, function($constraint) { - $constraint->upsize(); - }); + $this->image->scale( + height: $height + ); } /** @@ -224,4 +223,19 @@ private function resizeExact(int $width, int $height): void { $this->image->resize($width, $height); } + + /** + * Save image file + * + * @param string $path + * @return void + */ + private function save(string $path): void + { + $isSvg = $this->file->getExtension() === 'svg' || $this->file->getClientOriginalExtension() === 'svg'; + + $isSvg + ? $this->image->toPng()->save($path) + : $this->image->encode()->save($path); + } } diff --git a/tests/Support/Data/image.gif b/tests/Support/Data/image.gif index 8bae66a..378a755 100644 Binary files a/tests/Support/Data/image.gif and b/tests/Support/Data/image.gif differ diff --git a/tests/Support/LaruploadTestConsts.php b/tests/Support/LaruploadTestConsts.php index dd5e8aa..47235ae 100755 --- a/tests/Support/LaruploadTestConsts.php +++ b/tests/Support/LaruploadTestConsts.php @@ -75,7 +75,7 @@ class LaruploadTestConsts 'width' => 150, 'height' => 189, 'mime_type' => 'image/gif', - 'color' => '#0a660b', + 'color' => '#086e09', 'name' => [ 'hash' => '710bf7618c3a942d5c3279ff0bb282c1.gif', ]