Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"php": ">=5.3.0",
"php": ">=5.5.0",
"ext-gd": "*"
},
"suggest": {
Expand Down
24 changes: 24 additions & 0 deletions lib/ImageResize.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ImageResize
const CROPTOPCENTER = 6;

public $quality_jpg = 85;
public $quality_webp = 85;
public $quality_png = 6;
public $quality_truecolor = TRUE;

Expand Down Expand Up @@ -62,6 +63,10 @@ public static function createFromString($image_data)
*/
public function __construct($filename)
{
if(!defined('IMAGETYPE_WEBP')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define('IMAGETYPE_WEBP', 18);
}

$image_info = @getimagesize($filename);

if (!$image_info) {
Expand All @@ -87,6 +92,10 @@ public function __construct($filename)
$this->original_h = ImageSY($this->source_image);

break;

case IMAGETYPE_WEBP:
$this->source_image = imagecreatefromwebp($filename);
break;

case IMAGETYPE_PNG:
$this->source_image = imagecreatefrompng($filename);
Expand Down Expand Up @@ -164,6 +173,13 @@ public function save($filename, $image_type = null, $quality = null, $permission
$background = imagecolorallocate($dest_image, 255, 255, 255);
imagefilledrectangle($dest_image, 0, 0, $this->getDestWidth(), $this->getDestHeight(), $background);
break;

case IMAGETYPE_WEBP:
$dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight());

$background = imagecolorallocate($dest_image, 255, 255, 255);
imagefilledrectangle($dest_image, 0, 0, $this->getDestWidth(), $this->getDestHeight(), $background);
break;

case IMAGETYPE_PNG:
if (!$this->quality_truecolor && !imageistruecolor($this->source_image)) {
Expand Down Expand Up @@ -208,6 +224,14 @@ public function save($filename, $image_type = null, $quality = null, $permission

imagejpeg($dest_image, $filename, $quality);
break;

case IMAGETYPE_WEBP:
if ($quality === null) {
$quality = $this->quality_webp;
}

imagewebp($dest_image, $filename, $quality);
break;

case IMAGETYPE_PNG:
if ($quality === null) {
Expand Down