From aed682305173a67b2af1a56b8595445bec690e2b Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 7 Dec 2019 20:14:17 +0100 Subject: Add .webp image format support --- include/attach.php | 19 +++++++++++++------ include/photo/photo_driver.php | 2 ++ include/text.php | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index 80efe0838..952270949 100644 --- a/include/attach.php +++ b/include/attach.php @@ -56,6 +56,7 @@ function z_mime_content_type($filename) { 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'gif' => 'image/gif', + 'webp' => 'image/webp', 'bmp' => 'image/bmp', 'ico' => 'image/vnd.microsoft.icon', 'tiff' => 'image/tiff', @@ -616,7 +617,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $is_photo = 0; $gis = @getimagesize($src); logger('getimagesize: ' . print_r($gis,true), LOGGER_DATA); - if(($gis) && ($gis[2] === IMAGETYPE_GIF || $gis[2] === IMAGETYPE_JPEG || $gis[2] === IMAGETYPE_PNG)) { + if(($gis) && ($gis[2] === IMAGETYPE_GIF || $gis[2] === IMAGETYPE_JPEG || $gis[2] === IMAGETYPE_PNG || $gis[2] === IMAGETYPE_WEBP)) { $is_photo = 1; if($gis[2] === IMAGETYPE_GIF) $def_extension = '.gif'; @@ -624,6 +625,8 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $def_extension = '.jpg'; if($gis[2] === IMAGETYPE_PNG) $def_extension = '.png'; + if($gis[2] === IMAGETYPE_WEBP) + $def_extension = '.webp'; } // If we know it's a photo, over-ride the type in case the source system could not determine what it was @@ -908,7 +911,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { ); } - if($is_photo) { + if($is_photo && $r) { $args = array( 'source' => $source, 'visible' => $visible, 'resource_id' => $hash, 'album' => $pathname, 'os_syspath' => $os_basepath . $os_relpath, 'os_path' => $os_path, 'display_path' => $display_path, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct, 'options' => $options ); if($arr['contact_allow']) @@ -942,9 +945,15 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $args['deliver'] = $dosync; $p = photo_upload($channel,$observer,$args); - if($p['success']) { - $ret['body'] = $p['body']; + if($p['success']) + $ret['body'] = $p['body']; + else { + // Attach as ordinary file if image processing is failed + $x = q("UPDATE attach SET is_photo = 0 WHERE hash = '%s'", + dbesc($hash) + ); } + } if(($options !== 'update') && ($remove_when_processed)) @@ -2654,5 +2663,3 @@ function save_chunk($channel,$start,$end,$len) { $result['length'] = intval(filesize($new_path)); return $result; } - - diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index c11580bdc..284206161 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -135,6 +135,8 @@ function guess_image_type($filename, $headers = '') { $type = 'image/gif'; elseif(strpos(strtolower($filename),'png') !== false) $type = 'image/png'; + elseif(strpos(strtolower($filename),'webp') !== false) + $type = 'image/webp'; } } diff --git a/include/text.php b/include/text.php index eba41521d..87ed9f658 100644 --- a/include/text.php +++ b/include/text.php @@ -2992,6 +2992,7 @@ function getIconFromType($type) { 'image/jpeg' => 'fa-picture-o', 'image/png' => 'fa-picture-o', 'image/gif' => 'fa-picture-o', + 'image/webp' => 'fa-picture-o', 'image/svg+xml' => 'fa-picture-o', //Archive 'application/zip' => 'fa-file-archive-o', -- cgit v1.2.3