1 | <?php |
||
15 | class FileManipulator |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * Create all derived files for the given media. |
||
20 | * |
||
21 | * @param \Spatie\MediaLibrary\Media $media |
||
22 | */ |
||
23 | public function createDerivedFiles(Media $media) |
||
43 | |||
44 | /** |
||
45 | * Perform the given conversions for the given media. |
||
46 | * |
||
47 | * @param \Spatie\MediaLibrary\Conversion\ConversionCollection $conversions |
||
48 | * @param \Spatie\MediaLibrary\Media $media |
||
49 | */ |
||
50 | public function performConversions(ConversionCollection $conversions, Media $media) |
||
79 | |||
80 | /** |
||
81 | * Perform the conversion. |
||
82 | * |
||
83 | * @param \Spatie\MediaLibrary\Media $media |
||
84 | * @param Conversion $conversion |
||
85 | * @param string $copiedOriginalFile |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function performConversion(Media $media, Conversion $conversion, string $copiedOriginalFile) |
||
104 | |||
105 | /* |
||
106 | * Create a directory to store some working files. |
||
107 | */ |
||
108 | public function createTempDirectory() : string |
||
116 | |||
117 | protected function convertPdfToImage(string $pdfFile) : string |
||
118 | { |
||
119 | $imageFile = string($pdfFile)->pop('.').'.jpg'; |
||
120 | |||
121 | (new Pdf($pdfFile))->saveImage($imageFile); |
||
122 | |||
123 | return $imageFile; |
||
124 | } |
||
125 | |||
126 | protected function convertSvgToImage(string $svgFile) : string |
||
127 | { |
||
128 | $imageFile = string($svgFile)->pop('.').'.png'; |
||
129 | |||
130 | $image = new \Imagick(); |
||
131 | $image->readImage($svgFile); |
||
132 | $image->setBackgroundColor(new ImagickPixel('none')); |
||
133 | $image->setImageFormat("png32"); |
||
134 | |||
135 | file_put_contents($imageFile, $image); |
||
136 | |||
137 | return $imageFile; |
||
138 | } |
||
139 | |||
140 | /* |
||
141 | * Dispatch the given conversions. |
||
142 | */ |
||
143 | protected function dispatchQueuedConversions(Media $media, ConversionCollection $queuedConversions) |
||
155 | } |
||
156 |