setupImage(); } /* * 裁剪比例 格式:1/1 */ public function aspectRatio(float $value = 1) { $this->options['aspectRatio'] = $value; return $this; } protected function setupImage() { if (! isset($this->options['accept'])) { $this->options['accept'] = []; } $this->options['accept']['mimeTypes'] = 'image/*'; $this->options['isImage'] = true; } /** * @param array $options support: * [ * 'width' => 100, * 'height' => 100, * 'min_width' => 100, * 'min_height' => 100, * 'max_width' => 100, * 'max_height' => 100, * 'ratio' => 3/2, // (width / height) * ] * @return $this */ public function dimensions(array $options) { if (! $options) { return $this; } $this->mergeOptions(['dimensions' => $options]); foreach ($options as $k => &$v) { $v = "$k=$v"; } return $this->rules('dimensions:'.implode(',', $options)); } /** * Set ratio constraint. * * @param float $ratio width/height * @return $this */ public function ratio($ratio) { if ($ratio <= 0) { return $this; } return $this->dimensions(['ratio' => $ratio]); } /** * @param UploadedFile $file */ protected function prepareFile(UploadedFile $file) { $this->callInterventionMethods($file->getRealPath(), $file->getMimeType()); $this->uploadAndDeleteOriginalThumbnail($file); } }