Skip to content

Commit 622c36a

Browse files
authored
Merge pull request #157 from mostafaznv/dev
feat: add the ability to choose image processing library between `GD` and `Imagick`
2 parents 3df8372 + 76b20bb commit 622c36a

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

config/nova-ckeditor.php

+12
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@
7373

7474
'image-naming-method' => 'hash-file',
7575

76+
/*
77+
|--------------------------------------------------------------------------
78+
| Image Processing Library
79+
|--------------------------------------------------------------------------
80+
|
81+
|
82+
| Available methods: GD, IMAGICK
83+
|
84+
*/
85+
86+
'image-processing-library' => \Mostafaznv\NovaCkEditor\Enums\ImageLibrary::GD,
87+
7688
/*
7789
|--------------------------------------------------------------------------
7890
| Naming Method of Audio

docs/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* [Image Max Width](advanced-usage/configuration/image-max-width.md)
4646
* [Image Max Height](advanced-usage/configuration/image-max-height.md)
4747
* [Image Naming Method](advanced-usage/configuration/image-naming-method.md)
48+
* [Image Processing Library](advanced-usage/configuration/image-processing-library.md)
4849
* [Audio Naming Method](advanced-usage/configuration/audio-naming-method.md)
4950
* [File Naming Method](advanced-usage/configuration/audio-naming-method-1.md)
5051
* [Toolbars](advanced-usage/configuration/toolbars/README.md)

docs/advanced-usage/ckeditor-field-options/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ This section will guide you through the various methods and options available fo
44

55
Let's dive into the comprehensive set of features and functionalities offered by the CKEditor field in the following sections.
66

7-
\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
description: image-processing-library
3+
---
4+
5+
# Image Processing Library
6+
7+
| Property Name | Type | Default |
8+
| ------------------------ | ------------ | ------------------------------------ |
9+
| image-processing-library | ImageLibrary | <mark style="color:red;">`GD`</mark> |
10+
11+
12+
13+
This configuration option allows you to define the image processing library that will be used for handling image operations in the NovaCkEditor package.
14+
15+
16+
17+
**Available Methods:**
18+
19+
* <mark style="color:red;">GD</mark>: A lightweight and widely-supported image processing library.
20+
* <mark style="color:red;">IMAGICK</mark>: A more advanced library with additional features for image manipulation.
21+

src/Enums/ImageLibrary.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Mostafaznv\NovaCkEditor\Enums;
4+
5+
6+
enum ImageLibrary: string
7+
{
8+
case GD = 'GD';
9+
case IMAGICK = 'IMAGICK';
10+
}

src/ImageStorage.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55
use Illuminate\Http\UploadedFile;
66
use Intervention\Image\ImageManager;
77
use Intervention\Image\Interfaces\ImageInterface;
8+
use Mostafaznv\NovaCkEditor\Enums\ImageLibrary;
89
use Spatie\ImageOptimizer\OptimizerChainFactory;
910

1011

1112
class ImageStorage extends Storage
1213
{
14+
protected ImageLibrary $library;
15+
16+
1317
public function __construct(string $disk = 'image')
1418
{
1519
parent::__construct($disk);
1620

1721
$this->namingMethod = config('nova-ckeditor.image-naming-method');
22+
$this->library = config('nova-ckeditor.image-processing-library', ImageLibrary::GD);
1823
}
1924

2025
public static function make(string $disk = 'image'): self
@@ -72,7 +77,11 @@ protected function resize(UploadedFile $file): array
7277

7378
protected function resizeImage(UploadedFile $file, int $maxWidth, int $maxHeight): ImageInterface
7479
{
75-
$image = ImageManager::gd()->read($file->getRealPath());
80+
$manager = $this->library == ImageLibrary::GD
81+
? ImageManager::gd()
82+
: ImageManager::imagick();
83+
84+
$image = $manager->read($file->getRealPath());
7685

7786
return $image->scaleDown($maxWidth, $maxHeight);
7887
}

0 commit comments

Comments
 (0)