Skip to content

Commit 3595b8e

Browse files
committedMar 10, 2021
Add webp support for source images
1 parent 8454f5d commit 3595b8e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
 

‎LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-2020 Alex Yashkin
3+
Copyright (c) 2015-2021 Alex Yashkin
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎src/Creator.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Creator
5151
/**
5252
* @var array allowed mime types
5353
*/
54-
public static $mimeTypes = array('image/gif', 'image/jpeg', 'image/png');
54+
public static $mimeTypes = array('image/gif', 'image/jpeg', 'image/png', 'image/webp');
5555
/**
5656
* @var array allowed methods
5757
*/
@@ -211,6 +211,7 @@ public static function create($webroot, $path)
211211
$is_jpeg = $mime_type == 'image/jpeg';
212212
$is_png = $mime_type == 'image/png';
213213
$is_gif = $mime_type == 'image/gif';
214+
$is_webp = $mime_type == 'image/webp';
214215

215216
if ($as_jpeg) {
216217
$as_png = false;
@@ -464,6 +465,12 @@ public static function create($webroot, $path)
464465
$im = imagecreatefromgif($orig_path);
465466
} elseif ($is_png) {
466467
$im = imagecreatefrompng($orig_path);
468+
} elseif ($is_webp) {
469+
if (function_exists('imagecreatefromwebp')) {
470+
$im = imagecreatefromwebp($orig_path);
471+
} else {
472+
$im = false;
473+
}
467474
} else {
468475
$im = imagecreatefromjpeg($orig_path);
469476
}

0 commit comments

Comments
 (0)
Please sign in to comment.