bytic /
MediaLibrary
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace ByTIC\MediaLibrary\Media\Manipulators\Images; |
||||
| 4 | |||||
| 5 | use ByTIC\MediaLibrary\Conversions\Conversion; |
||||
| 6 | use ByTIC\MediaLibrary\Conversions\Manipulations\Manipulation; |
||||
| 7 | use ByTIC\MediaLibrary\Conversions\Manipulations\ManipulationSequence; |
||||
| 8 | use ByTIC\MediaLibrary\Media\Manipulators\AbstractManipulator; |
||||
| 9 | use ByTIC\MediaLibrary\Media\Manipulators\Images\Drivers\AbstractDriver; |
||||
| 10 | use ByTIC\MediaLibrary\Media\Manipulators\Images\Drivers\ImagineDriver; |
||||
| 11 | use ByTIC\MediaLibrary\Media\Media; |
||||
| 12 | use Nip\Collection; |
||||
| 13 | |||||
| 14 | /** |
||||
| 15 | * Class ImageManipulator. |
||||
| 16 | */ |
||||
| 17 | class ImageManipulator extends AbstractManipulator |
||||
| 18 | { |
||||
| 19 | protected $driver = null; |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * @param Media $media |
||||
| 23 | * @param Conversion $conversion |
||||
| 24 | */ |
||||
| 25 | public function performConversion(Media $media, Conversion $conversion) |
||||
| 26 | { |
||||
| 27 | $manipulations = $this->prependCroperManipulations($media, $conversion->getManipulations()); |
||||
| 28 | $imageContent = $this->getDriver()->manipulate( |
||||
| 29 | $media->getFile()->read(), |
||||
| 30 | $manipulations, |
||||
| 31 | $media->getExtension() |
||||
| 32 | ); |
||||
| 33 | |||||
| 34 | $path = $media->getPath($conversion->getName()); |
||||
| 35 | $media->getCollection()->getFilesystem()->put($path, $imageContent); |
||||
|
0 ignored issues
–
show
|
|||||
| 36 | } |
||||
| 37 | |||||
| 38 | /** |
||||
| 39 | * @param Media $media |
||||
| 40 | * @param ManipulationSequence $manipulations |
||||
| 41 | * @return ManipulationSequence |
||||
| 42 | */ |
||||
| 43 | protected function prependCroperManipulations($media, $manipulations) |
||||
| 44 | { |
||||
| 45 | if (!isset($media->cropperData)) { |
||||
| 46 | return $manipulations; |
||||
| 47 | } |
||||
| 48 | $data = array_map('intval', $media->cropperData); |
||||
| 49 | $manipulations->prepend(Manipulation::create('crop', $data['width'], $data['height'], $data['x'], $data['y'])); |
||||
| 50 | return $manipulations; |
||||
| 51 | } |
||||
| 52 | |||||
| 53 | /** |
||||
| 54 | * @return AbstractDriver |
||||
| 55 | */ |
||||
| 56 | 1 | public function getDriver() |
|||
| 57 | { |
||||
| 58 | 1 | if ($this->driver === null) { |
|||
| 59 | 1 | $this->driver = $this->newDriver(); |
|||
| 60 | } |
||||
| 61 | |||||
| 62 | 1 | return $this->driver; |
|||
| 63 | } |
||||
| 64 | |||||
| 65 | /** |
||||
| 66 | * @return ImagineDriver |
||||
| 67 | */ |
||||
| 68 | 1 | protected function newDriver() |
|||
| 69 | { |
||||
| 70 | 1 | return new ImagineDriver(); |
|||
| 71 | } |
||||
| 72 | |||||
| 73 | /** |
||||
| 74 | * @return bool |
||||
| 75 | */ |
||||
| 76 | 4 | public function requirementsAreInstalled(): bool |
|||
| 77 | { |
||||
| 78 | 4 | return true; |
|||
| 79 | } |
||||
| 80 | |||||
| 81 | /** |
||||
| 82 | * {@inheritdoc} |
||||
| 83 | */ |
||||
| 84 | 4 | public function supportedExtensions(): Collection |
|||
| 85 | { |
||||
| 86 | 4 | return new Collection(['png', 'jpg', 'jpeg', 'gif']); |
|||
|
0 ignored issues
–
show
The class
Nip\Collection has been deprecated: Use new Collection class from Nip/Collection repo
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 87 | } |
||||
| 88 | |||||
| 89 | /** |
||||
| 90 | * {@inheritdoc} |
||||
| 91 | */ |
||||
| 92 | public function supportedMimeTypes(): Collection |
||||
| 93 | { |
||||
| 94 | return new Collection(['image/jpeg', 'image/gif', 'image/png']); |
||||
|
0 ignored issues
–
show
The class
Nip\Collection has been deprecated: Use new Collection class from Nip/Collection repo
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 95 | } |
||||
| 96 | } |
||||
| 97 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.