88use League \Flysystem \FilesystemOperator ;
99use League \Flysystem \FilesystemReader ;
1010use League \Flysystem \StorageAttributes ;
11- use SixtyEightPublishers \FileStorage \Config \ConfigInterface ;
1211use SixtyEightPublishers \FileStorage \Exception \FilesystemException ;
1312use SixtyEightPublishers \FileStorage \PathInfoInterface as FilePathInfoInterface ;
1413use SixtyEightPublishers \FileStorage \Resource \ResourceInterface ;
15- use SixtyEightPublishers \ImageStorage \Config \Config ;
1614use SixtyEightPublishers \ImageStorage \Exception \InvalidArgumentException ;
1715use SixtyEightPublishers \ImageStorage \PathInfoInterface as ImagePathInfoInterface ;
1816use SixtyEightPublishers \ImageStorage \Resource \ResourceInterface as ImageResourceInterface ;
@@ -26,7 +24,6 @@ final class ImagePersister implements ImagePersisterInterface
2624{
2725 public function __construct (
2826 private readonly FilesystemOperator $ filesystemOperator ,
29- private readonly ConfigInterface $ config ,
3027 ) {}
3128
3229 public function getFilesystem (): FilesystemOperator
@@ -63,7 +60,7 @@ public function save(ResourceInterface $resource, array $config = []): string
6360 $ flushCache = self ::FILESYSTEM_PREFIX_SOURCE === $ prefix && $ this ->exists ($ pathInfo );
6461
6562 try {
66- $ this ->filesystemOperator ->write ($ prefix . $ path , $ this -> encodeImage ( $ resource ), $ config );
63+ $ this ->filesystemOperator ->write ($ prefix . $ path , $ resource -> getEncodedImage ( ), $ config );
6764
6865 if ($ flushCache ) {
6966 $ this ->delete ($ pathInfo , [
@@ -127,24 +124,6 @@ public function delete(FilePathInfoInterface $pathInfo, array $config = []): voi
127124 $ this ->deleteFile (self ::FILESYSTEM_PREFIX_SOURCE . $ pathInfo ->getPath (), $ config );
128125 }
129126
130- private function encodeImage (ImageResourceInterface $ resource ): string
131- {
132- if (!$ resource ->hasBeenModified ()) {
133- $ contents = @file_get_contents ($ resource ->getLocalFilename ());
134-
135- if (false !== $ contents ) {
136- return $ contents ;
137- }
138- }
139-
140- $ quality = (int ) ($ resource ->getEncodeQuality () ?? $ this ->config [Config::ENCODE_QUALITY ] ?? 90 );
141- $ format = $ resource ->getEncodeFormat () ?? '' ;
142- $ image = $ resource ->getSource ();
143- $ image = $ image ->encode ($ format , $ quality );
144-
145- return $ image ->getEncoded ();
146- }
147-
148127 /**
149128 * @param array<string, mixed> $config
150129 * @throws FilesystemException
0 commit comments