kopia lustrzana https://github.com/pixelfed/pixelfed
				
				
				
			Add WebP support
							rodzic
							
								
									1baf378497
								
							
						
					
					
						commit
						069a0e4ae1
					
				|  | @ -26,6 +26,7 @@ trait AdminSettingsController | ||||||
| 		$png = in_array('image/png', $types); | 		$png = in_array('image/png', $types); | ||||||
| 		$gif = in_array('image/gif', $types); | 		$gif = in_array('image/gif', $types); | ||||||
| 		$mp4 = in_array('video/mp4', $types); | 		$mp4 = in_array('video/mp4', $types); | ||||||
|  | 		$webp = in_array('image/webp', $types); | ||||||
| 
 | 
 | ||||||
| 		// $system = [
 | 		// $system = [
 | ||||||
| 		// 	'permissions' => is_writable(base_path('storage')) && is_writable(base_path('bootstrap')),
 | 		// 	'permissions' => is_writable(base_path('storage')) && is_writable(base_path('bootstrap')),
 | ||||||
|  | @ -39,6 +40,7 @@ trait AdminSettingsController | ||||||
| 			'png', | 			'png', | ||||||
| 			'gif', | 			'gif', | ||||||
| 			'mp4', | 			'mp4', | ||||||
|  | 			'webp', | ||||||
| 			'rules', | 			'rules', | ||||||
| 			'cloud_storage', | 			'cloud_storage', | ||||||
| 			'cloud_disk', | 			'cloud_disk', | ||||||
|  | @ -60,6 +62,7 @@ trait AdminSettingsController | ||||||
| 			'type_png' => 'nullable', | 			'type_png' => 'nullable', | ||||||
| 			'type_gif' => 'nullable', | 			'type_gif' => 'nullable', | ||||||
| 			'type_mp4' => 'nullable', | 			'type_mp4' => 'nullable', | ||||||
|  | 			'type_webp' => 'nullable', | ||||||
| 		]); | 		]); | ||||||
| 
 | 
 | ||||||
| 		if($request->filled('rule_delete')) { | 		if($request->filled('rule_delete')) { | ||||||
|  | @ -83,6 +86,7 @@ trait AdminSettingsController | ||||||
| 			'type_png' => 'image/png', | 			'type_png' => 'image/png', | ||||||
| 			'type_gif' => 'image/gif', | 			'type_gif' => 'image/gif', | ||||||
| 			'type_mp4' => 'video/mp4', | 			'type_mp4' => 'video/mp4', | ||||||
|  | 			'type_webp' => 'image/webp', | ||||||
| 		]; | 		]; | ||||||
| 
 | 
 | ||||||
| 		foreach ($mimes as $key => $value) { | 		foreach ($mimes as $key => $value) { | ||||||
|  |  | ||||||
|  | @ -136,6 +136,7 @@ class ComposeController extends Controller | ||||||
| 		switch ($media->mime) { | 		switch ($media->mime) { | ||||||
| 			case 'image/jpeg': | 			case 'image/jpeg': | ||||||
| 			case 'image/png': | 			case 'image/png': | ||||||
|  | 			case 'image/webp': | ||||||
| 			ImageOptimize::dispatch($media); | 			ImageOptimize::dispatch($media); | ||||||
| 			break; | 			break; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -16,68 +16,68 @@ use App\Jobs\MediaPipeline\MediaStoragePipeline; | ||||||
| 
 | 
 | ||||||
| class ImageUpdate implements ShouldQueue | class ImageUpdate implements ShouldQueue | ||||||
| { | { | ||||||
|     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | 	use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||||||
| 
 | 
 | ||||||
|     protected $media; | 	protected $media; | ||||||
| 
 | 
 | ||||||
|     protected $protectedMimes = [ | 	protected $protectedMimes = [ | ||||||
|         'image/jpeg', | 		'image/jpeg', | ||||||
|         'image/png', | 		'image/png', | ||||||
|     ]; | 		'image/webp' | ||||||
|  | 	]; | ||||||
| 
 | 
 | ||||||
|     /** | 	/** | ||||||
|      * Delete the job if its models no longer exist. | 	 * Delete the job if its models no longer exist. | ||||||
|      * | 	 * | ||||||
|      * @var bool | 	 * @var bool | ||||||
|      */ | 	 */ | ||||||
|     public $deleteWhenMissingModels = true; | 	public $deleteWhenMissingModels = true; | ||||||
|      |  | ||||||
|     /** |  | ||||||
|      * Create a new job instance. |  | ||||||
|      * |  | ||||||
|      * @return void |  | ||||||
|      */ |  | ||||||
|     public function __construct(Media $media) |  | ||||||
|     { |  | ||||||
|         $this->media = $media; |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     /** | 	/** | ||||||
|      * Execute the job. | 	 * Create a new job instance. | ||||||
|      * | 	 * | ||||||
|      * @return void | 	 * @return void | ||||||
|      */ | 	 */ | ||||||
|     public function handle() | 	public function __construct(Media $media) | ||||||
|     { | 	{ | ||||||
|         $media = $this->media; | 		$this->media = $media; | ||||||
|         if(!$media) { | 	} | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|         $path = storage_path('app/'.$media->media_path); |  | ||||||
|         $thumb = storage_path('app/'.$media->thumbnail_path); |  | ||||||
|          |  | ||||||
|         if (!is_file($path)) { |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         if (in_array($media->mime, $this->protectedMimes) == true) { | 	/** | ||||||
|             ImageOptimizer::optimize($thumb); | 	 * Execute the job. | ||||||
|             if(!$media->skip_optimize) { | 	 * | ||||||
|                 ImageOptimizer::optimize($path); | 	 * @return void | ||||||
|             } | 	 */ | ||||||
|         } | 	public function handle() | ||||||
|  | 	{ | ||||||
|  | 		$media = $this->media; | ||||||
|  | 		if(!$media) { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 		$path = storage_path('app/'.$media->media_path); | ||||||
|  | 		$thumb = storage_path('app/'.$media->thumbnail_path); | ||||||
| 
 | 
 | ||||||
|         if (!is_file($path) || !is_file($thumb)) { | 		if (!is_file($path)) { | ||||||
|             return; | 			return; | ||||||
|         } | 		} | ||||||
| 
 | 
 | ||||||
|         $photo_size = filesize($path); | 		if (in_array($media->mime, $this->protectedMimes) == true) { | ||||||
|         $thumb_size = filesize($thumb); | 			ImageOptimizer::optimize($thumb); | ||||||
|         $total = ($photo_size + $thumb_size); | 			if(!$media->skip_optimize) { | ||||||
|         $media->size = $total; | 				ImageOptimizer::optimize($path); | ||||||
|         $media->save(); | 			} | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
|         MediaStoragePipeline::dispatch($media); | 		if (!is_file($path) || !is_file($thumb)) { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
|     } | 		$photo_size = filesize($path); | ||||||
|  | 		$thumb_size = filesize($thumb); | ||||||
|  | 		$total = ($photo_size + $thumb_size); | ||||||
|  | 		$media->size = $total; | ||||||
|  | 		$media->save(); | ||||||
|  | 
 | ||||||
|  | 		MediaStoragePipeline::dispatch($media); | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -15,7 +15,8 @@ class Image | ||||||
| 	public $orientation; | 	public $orientation; | ||||||
| 	public $acceptedMimes = [ | 	public $acceptedMimes = [ | ||||||
| 		'image/png', | 		'image/png', | ||||||
| 		'image/jpeg' | 		'image/jpeg', | ||||||
|  | 		'image/webp' | ||||||
| 	]; | 	]; | ||||||
| 
 | 
 | ||||||
| 	public function __construct() | 	public function __construct() | ||||||
|  |  | ||||||
|  | @ -238,8 +238,12 @@ | ||||||
| 					<label class="custom-control-label" for="mediaType3"><span class="border border-dark px-1 rounded font-weight-bold">GIF</span></label> | 					<label class="custom-control-label" for="mediaType3"><span class="border border-dark px-1 rounded font-weight-bold">GIF</span></label> | ||||||
| 				</div> | 				</div> | ||||||
| 				<div class="custom-control custom-checkbox mt-2"> | 				<div class="custom-control custom-checkbox mt-2"> | ||||||
| 					<input type="checkbox" name="type_mp4" class="custom-control-input" id="mediaType4" {{$mp4 ? 'checked' : ''}}> | 					<input type="checkbox" name="type_webp" class="custom-control-input" id="mediaType4" {{$webp ? 'checked' : ''}}> | ||||||
| 					<label class="custom-control-label" for="mediaType4"><span class="border border-dark px-1 rounded font-weight-bold">MP4</span></label> | 					<label class="custom-control-label" for="mediaType4"><span class="border border-dark px-1 rounded font-weight-bold">WebP</span></label> | ||||||
|  | 				</div> | ||||||
|  | 				<div class="custom-control custom-checkbox mt-2"> | ||||||
|  | 					<input type="checkbox" name="type_mp4" class="custom-control-input" id="mediaType5" {{$mp4 ? 'checked' : ''}}> | ||||||
|  | 					<label class="custom-control-label" for="mediaType5"><span class="border border-dark px-1 rounded font-weight-bold">MP4</span></label> | ||||||
| 				</div> | 				</div> | ||||||
| 				<p class="help-text small text-muted mt-3 mb-0">Allowed media types.</p> | 				<p class="help-text small text-muted mt-3 mb-0">Allowed media types.</p> | ||||||
| 			</div> | 			</div> | ||||||
|  |  | ||||||
		Ładowanie…
	
		Reference in New Issue
	
	 Daniel Supernault
						Daniel Supernault