Skip to content

Commit

Permalink
image/webp for Image lib
Browse files Browse the repository at this point in the history
  • Loading branch information
NielBuys committed May 10, 2024
1 parent 9613532 commit 1ff6a1a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions system/language/english/imglib_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
$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.';
$lang['imglib_jpg_not_supported'] = 'JPG images are not supported.';
$lang['imglib_png_not_supported'] = 'PNG images are not supported.';
$lang['imglib_webp_not_supported'] = 'WEBP images are not supported.';
$lang['imglib_jpg_or_png_required'] = 'The image resize protocol specified in your preferences only works with JPEG or PNG image types.';
$lang['imglib_copy_error'] = 'An error was encountered while attempting to replace the file. Please make sure your file directory is writable.';
$lang['imglib_rotate_unsupported'] = 'Image rotation does not appear to be supported by your server.';
Expand Down
26 changes: 26 additions & 0 deletions system/libraries/Image_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,10 @@ public function image_process_netpbm($action = 'resize')
$cmd_in = 'pngtopnm';
$cmd_out = 'ppmtopng';
break;
case 18 :
$cmd_in = 'webptopnm';
$cmd_out = 'ppmtowebp';
break;
}

if ($action === 'crop')
Expand Down Expand Up @@ -1480,6 +1484,13 @@ public function image_create_gd($path = '', $image_type = '')
}

return imagecreatefrompng($path);
case 18:
if ( ! function_exists('imagecreatefromwebp'))
{
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_webp_not_supported'));
return FALSE;
}
return imagecreatefromwebp($path);
default:
$this->set_error(array('imglib_unsupported_imagecreate'));
return FALSE;
Expand Down Expand Up @@ -1540,6 +1551,19 @@ public function image_save_gd($resource)
return FALSE;
}
break;
case 18:
if ( ! function_exists('imagewebp'))
{
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_webp_not_supported'));
return FALSE;
}

if ( ! @imagewebp($resource, $this->full_dst_path))
{
$this->set_error('imglib_save_failed');
return FALSE;
}
break;
default:
$this->set_error(array('imglib_unsupported_imagecreate'));
return FALSE;
Expand Down Expand Up @@ -1572,6 +1596,8 @@ public function image_display_gd($resource)
break;
case 3 : imagepng($resource);
break;
case 18 : imagewebp($resource);
break;
default: echo 'Unable to display the image';
break;
}
Expand Down

0 comments on commit 1ff6a1a

Please sign in to comment.