Skip to content

Commit 1ff6a1a

Browse files
committed
image/webp for Image lib
1 parent 9613532 commit 1ff6a1a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

system/language/english/imglib_lang.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
$lang['imglib_gif_not_supported'] = 'GIF images are often not supported due to licensing restrictions. You may have to use JPG or PNG images instead.';
4646
$lang['imglib_jpg_not_supported'] = 'JPG images are not supported.';
4747
$lang['imglib_png_not_supported'] = 'PNG images are not supported.';
48+
$lang['imglib_webp_not_supported'] = 'WEBP images are not supported.';
4849
$lang['imglib_jpg_or_png_required'] = 'The image resize protocol specified in your preferences only works with JPEG or PNG image types.';
4950
$lang['imglib_copy_error'] = 'An error was encountered while attempting to replace the file. Please make sure your file directory is writable.';
5051
$lang['imglib_rotate_unsupported'] = 'Image rotation does not appear to be supported by your server.';

system/libraries/Image_lib.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,10 @@ public function image_process_netpbm($action = 'resize')
954954
$cmd_in = 'pngtopnm';
955955
$cmd_out = 'ppmtopng';
956956
break;
957+
case 18 :
958+
$cmd_in = 'webptopnm';
959+
$cmd_out = 'ppmtowebp';
960+
break;
957961
}
958962

959963
if ($action === 'crop')
@@ -1480,6 +1484,13 @@ public function image_create_gd($path = '', $image_type = '')
14801484
}
14811485

14821486
return imagecreatefrompng($path);
1487+
case 18:
1488+
if ( ! function_exists('imagecreatefromwebp'))
1489+
{
1490+
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_webp_not_supported'));
1491+
return FALSE;
1492+
}
1493+
return imagecreatefromwebp($path);
14831494
default:
14841495
$this->set_error(array('imglib_unsupported_imagecreate'));
14851496
return FALSE;
@@ -1540,6 +1551,19 @@ public function image_save_gd($resource)
15401551
return FALSE;
15411552
}
15421553
break;
1554+
case 18:
1555+
if ( ! function_exists('imagewebp'))
1556+
{
1557+
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_webp_not_supported'));
1558+
return FALSE;
1559+
}
1560+
1561+
if ( ! @imagewebp($resource, $this->full_dst_path))
1562+
{
1563+
$this->set_error('imglib_save_failed');
1564+
return FALSE;
1565+
}
1566+
break;
15431567
default:
15441568
$this->set_error(array('imglib_unsupported_imagecreate'));
15451569
return FALSE;
@@ -1572,6 +1596,8 @@ public function image_display_gd($resource)
15721596
break;
15731597
case 3 : imagepng($resource);
15741598
break;
1599+
case 18 : imagewebp($resource);
1600+
break;
15751601
default: echo 'Unable to display the image';
15761602
break;
15771603
}

0 commit comments

Comments
 (0)