$this->init(
null,
- array('jpeg', 'jpg', 'png', 'gif'),
+ array('jpeg', 'jpg', 'png', 'gif', 'webp'),
array(
'jpg' => 'image/jpeg',
'png' => 'image/png',
- 'gif' => 'image/gif'
+ 'gif' => 'image/gif',
+ 'webp' => 'image/webp'
)
);
$this->format = 'gif';
$this->mime = 'image/gif';
return true;
+ } elseif (file_exists($file_wo_ext . '.webp')) {
+ $this->file_path = realpath($file_wo_ext . '.webp');
+ $this->format = 'webp';
+ $this->mime = 'image/webp';
+ return true;
}
return false;
}
case 'gif':
$this->mime = 'image/gif';
break;
+ case 'webp':
+ $this->mime = 'image/webp';
+ break;
}
$this->file_path = realpath($file_wo_ext . '.' . $this->format);
return true;
//return unlink($file_wo_ext . '.gif');
$_file = $file_wo_ext . '.gif';
$success = unlink($_file);
+ } elseif (file_exists($file_wo_ext . '.webp')) {
+ //return unlink($file_wo_ext . '.webp');
+ $_file = $file_wo_ext . '.webp';
+ $success = unlink($_file);
}
if ($_file !== null && $success !== true) {
return false;
}
break;
+ case 'webp':
+ if (!$gdinfo['WebP Support']) {
+ Analog::log(
+ '[' . $class . '] GD has no WebP Support - ' .
+ 'pictures could not be resized!',
+ Analog::ERROR
+ );
+ return false;
+ }
+ break;
+
default:
return false;
}
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $w, $h, $cur_width, $cur_height);
imagegif($thumb, $dest);
break;
+ case 'webp':
+ $image = imagecreatefromwebp($source);
+ imagecopyresampled($thumb, $image, 0, 0, 0, 0, $w, $h, $cur_width, $cur_height);
+ imagewebp($thumb, $dest);
+ break;
}
} else {
Analog::log(
$this->assertNull($picture->getDestDir());
$this->assertNull($picture->getFileName());
- $expected_exts = ['jpeg', 'jpg', 'png', 'gif'];
+ $expected_exts = ['jpeg', 'jpg', 'png', 'gif', 'webp'];
$this->assertSame(implode(', ', $expected_exts), $picture->getAllowedExts());
$expected_mimes = [
'jpg' => 'image/jpeg',
'png' => 'image/png',
- 'gif' => 'image/gif'
+ 'gif' => 'image/gif',
+ 'webp' => 'image/webp'
];
$this->assertSame($expected_mimes, $picture->getAllowedMimeTypes());
$this->picture->getErrorMessage(\Galette\Core\Picture::INVALID_FILENAME)
);
$this->assertSame(
- 'File extension is not allowed, only jpeg, jpg, png, gif files are.',
+ 'File extension is not allowed, only jpeg, jpg, png, gif, webp files are.',
$this->picture->getErrorMessage(\Galette\Core\Picture::INVALID_EXTENSION)
);
$this->assertSame(