php laravel:save_image

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php laravel:save_image相关的知识,希望对你有一定的参考价值。

<?php
class MeetingPrizeExport implements FromCollection, WithHeadings, Responsable, WithMapping, WithStrictNullComparison, WithEvents
{
	use Exportable;
	
	/**
	 * 注册事件
	 */
	public function registerEvents(): array
	{
		return [
			AfterSheet::class => function (AfterSheet $event) {
				$worksheet = $event->sheet->getDelegate();
				$worksheet->getColumnDimension('A')->setAutoSize(true);
				$worksheet->getColumnDimension('B')->setWidth(12);
				$worksheet->getColumnDimension('C')->setWidth(8);
				$worksheet->getColumnDimension('D')->setWidth(12);
				$worksheet->getColumnDimension('E')->setWidth(8);
				$worksheet->getColumnDimension('F')->setWidth(15);
				$worksheet->getColumnDimension('G')->setWidth(8);
				$this->collection()->each(function ($item, $key) use ($worksheet) {
					$disk  = \Storage::disk('local');
					$index = ($key + 2);
					if (preg_match("/^data:image\/(?<extension>(?:png|gif|jpg|jpeg));base64,(?<image>.+)$/", $item->user->face_image, $matchings)) {
						$imageData = base64_decode($matchings['image']);
						$extension = $matchings['extension'];
						$filename  = sprintf('user-%s.%s', $item->user->id, $extension);
						$disk->put('face_image/' . $filename, $imageData);
						$url     = $disk->url('app/face_image/' . $filename);
						$path    = base_path($url);
						$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
						$drawing->setName('Logo');
						$drawing->setDescription('Logo');
						$drawing->setPath($path);
						$drawing->setCoordinates('F' . $index);
						$drawing->setHeight(55);
						$drawing->setWorksheet($worksheet);
					}
					$worksheet->getRowDimension($index)->setRowHeight(55);
				});
			},
		];
	}
}

以上是关于php laravel:save_image的主要内容,如果未能解决你的问题,请参考以下文章

php [Laravel Logs] Como loguear cosas con laravel #laravel #php

Laravel 4.2 + Laravel Valet + PHP 7 = 需要 Mcrypt PHP 扩展

PHP笔记-laravel环境搭建(Laravel5.8.35版本)

《PHP框架Laravel学习》系列分享专栏

php [Laravel - 自定义错误消息] Laravel 5.4其他登录条件 - 添加自定义错误消息。 #All #Script #Laravel #Php

Aws-sdk-php-laravel 在 laravel 5.2 中得到 500 错误