Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 63aea93

Browse files
Merge pull request #144 from peter279k/issue_#136
Resolves issue #136
2 parents d12d8cf + 652999c commit 63aea93

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

‎lib/ImageResize.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ImageResize
4848
protected $source_h;
4949

5050
protected $source_info;
51-
51+
5252
protected $filters = [];
5353

5454
/**
@@ -110,23 +110,32 @@ public function __construct($filename)
110110
}
111111

112112
$finfo = finfo_open(FILEINFO_MIME_TYPE);
113+
$checkWebp = false;
113114
if (strstr(finfo_file($finfo, $filename), 'image') === false) {
114-
throw new ImageResizeException('Unsupported file type');
115+
if (version_compare(PHP_VERSION, '5.6.0', '<=')) {
116+
if (strstr(file_get_contents($filename), 'WEBPVP8') !== false) {
117+
$checkWebp = true;
118+
$this->source_type = IMAGETYPE_WEBP;
119+
}
120+
121+
} else {
122+
throw new ImageResizeException('Unsupported file type');
123+
}
115124
}
116125

117126
if (!$image_info = getimagesize($filename, $this->source_info)) {
118127
$image_info = getimagesize($filename);
119128
}
120129

121-
if (!$image_info) {
122-
throw new ImageResizeException('Could not read file');
123-
}
130+
if (!$checkWebp) {
131+
if (!$image_info) {
132+
throw new ImageResizeException('Could not read file');
133+
}
124134

125-
list(
126-
$this->original_w,
127-
$this->original_h,
128-
$this->source_type
129-
) = $image_info;
135+
$this->original_w = $image_info[0];
136+
$this->original_h = $image_info[1];
137+
$this->source_type = $image_info[2];
138+
}
130139

131140
switch ($this->source_type) {
132141
case IMAGETYPE_GIF:
@@ -147,10 +156,10 @@ public function __construct($filename)
147156
break;
148157

149158
case IMAGETYPE_WEBP:
150-
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
151-
throw new ImageResizeException('For WebP support PHP >= 5.5.0 is required');
152-
}
153159
$this->source_image = imagecreatefromwebp($filename);
160+
$this->original_w = imagesx($this->source_image);
161+
$this->original_h = imagesy($this->source_image);
162+
154163
break;
155164

156165
default:
@@ -300,7 +309,7 @@ public function save($filename, $image_type = null, $quality = null, $permission
300309
$this->dest_y = 0;
301310
}
302311
}
303-
312+
304313
imagecopyresampled(
305314
$dest_image,
306315
$this->source_image,
@@ -313,7 +322,7 @@ public function save($filename, $image_type = null, $quality = null, $permission
313322
$this->source_w,
314323
$this->source_h
315324
);
316-
325+
317326
if ($this->gamma_correct) {
318327
imagegammacorrect($dest_image, 1.0, 2.2);
319328
}

‎test/ImageResizeTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ public function testLoadPng()
5858
$this->assertInstanceOf('\Gumlet\ImageResize', $resize);
5959
}
6060

61+
public function testLoadWebp()
62+
{
63+
$image = __DIR__ . '/ressources/test_webp.webp';
64+
$resize = new ImageResize($image);
65+
66+
$this->assertEquals(IMAGETYPE_WEBP, $resize->source_type);
67+
$this->assertInstanceOf('\Gumlet\ImageResize', $resize);
68+
}
69+
6170
public function testLoadString()
6271
{
6372
$resize = ImageResize::createFromString(base64_decode($this->image_string));

‎test/ressources/test_webp.webp

29.6 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /