aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Module/Embedphotos.php2
-rw-r--r--Zotlabs/Module/Help.php5
-rw-r--r--Zotlabs/Photo/PhotoGd.php18
-rw-r--r--Zotlabs/Photo/PhotoImagick.php30
-rw-r--r--Zotlabs/Storage/File.php2
-rwxr-xr-xboot.php11
-rw-r--r--include/attach.php19
-rw-r--r--include/photo/photo_driver.php2
-rw-r--r--include/text.php1
9 files changed, 67 insertions, 23 deletions
diff --git a/Zotlabs/Module/Embedphotos.php b/Zotlabs/Module/Embedphotos.php
index 6a88513dc..9b0884197 100644
--- a/Zotlabs/Module/Embedphotos.php
+++ b/Zotlabs/Module/Embedphotos.php
@@ -68,6 +68,8 @@ class Embedphotos extends \Zotlabs\Web\Controller {
$ext = '.png';
elseif($r[0]['mimetype'] === 'image/gif')
$ext = '.gif';
+ elseif($r[0]['mimetype'] === 'image/webp')
+ $exp = '.webp';
else
$ext = EMPTY_STR;
diff --git a/Zotlabs/Module/Help.php b/Zotlabs/Module/Help.php
index f1b1acaef..ce05035b3 100644
--- a/Zotlabs/Module/Help.php
+++ b/Zotlabs/Module/Help.php
@@ -66,7 +66,10 @@ class Help extends \Zotlabs\Web\Controller {
case IMAGETYPE_PNG:
header("Content-Type: image/png");
break;
- default:
+ case IMAGETYPE_WEBP:
+ header("Content-Type: image/webp");
+ break;
+ default:
break;
}
header("Content-Length: " . filesize($realpath));
diff --git a/Zotlabs/Photo/PhotoGd.php b/Zotlabs/Photo/PhotoGd.php
index 4054e1866..c54fa6a7d 100644
--- a/Zotlabs/Photo/PhotoGd.php
+++ b/Zotlabs/Photo/PhotoGd.php
@@ -13,12 +13,16 @@ class PhotoGd extends PhotoDriver {
* @see \Zotlabs\Photo\PhotoDriver::supportedTypes()
*/
public function supportedTypes() {
+
$t = [];
+
$t['image/jpeg'] = 'jpg';
if(imagetypes() & IMG_PNG)
$t['image/png'] = 'png';
if(imagetypes() & IMG_GIF)
$t['image/gif'] = 'gif';
+ if(imagetypes() & IMG_WEBP)
+ $t['image/webp'] = 'webp';
return $t;
}
@@ -142,6 +146,7 @@ class PhotoGd extends PhotoDriver {
* @see \Zotlabs\Photo\PhotoDriver::imageString()
*/
public function imageString() {
+
if(! $this->is_valid())
return false;
@@ -150,23 +155,32 @@ class PhotoGd extends PhotoDriver {
ob_start();
switch($this->getType()){
+
case 'image/png':
$quality = get_config('system', 'png_quality');
if((! $quality) || ($quality > 9))
$quality = PNG_QUALITY;
-
\imagepng($this->image, NULL, $quality);
break;
+
+ case 'image/webp':
+ $quality = get_config('system', 'webp_quality');
+ if((! $quality) || ($quality > 100))
+ $quality = WEBP_QUALITY;
+ \imagewebp($this->image, NULL, $quality);
+ break;
+
case 'image/jpeg':
// gd can lack imagejpeg(), but we verify during installation it is available
+
default:
$quality = get_config('system', 'jpeg_quality');
if((! $quality) || ($quality > 100))
$quality = JPEG_QUALITY;
-
\imagejpeg($this->image, NULL, $quality);
break;
}
+
$string = ob_get_contents();
ob_end_clean();
diff --git a/Zotlabs/Photo/PhotoImagick.php b/Zotlabs/Photo/PhotoImagick.php
index a7026e8ca..0a08d19e6 100644
--- a/Zotlabs/Photo/PhotoImagick.php
+++ b/Zotlabs/Photo/PhotoImagick.php
@@ -8,19 +8,16 @@ namespace Zotlabs\Photo;
class PhotoImagick extends PhotoDriver {
public function supportedTypes() {
- return [
+
+ $ret = [
'image/jpeg' => 'jpg',
'image/png' => 'png',
- 'image/gif' => 'gif',
+ 'image/gif' => 'gif'
];
- }
+ if(\Imagick::queryFormats("WEBP"))
+ $ret['image/webp'] = 'webp';
- private function get_FormatsMap() {
- return [
- 'image/jpeg' => 'JPG',
- 'image/png' => 'PNG',
- 'image/gif' => 'GIF',
- ];
+ return $ret;
}
@@ -42,8 +39,8 @@ class PhotoImagick extends PhotoDriver {
* Setup the image to the format it will be saved to
*/
- $map = $this->get_FormatsMap();
- $format = $map[$type];
+ $map = $this->supportedTypes();
+ $format = strtoupper($map[$type]);
if($this->image) {
$this->image->setFormat($format);
@@ -58,6 +55,7 @@ class PhotoImagick extends PhotoDriver {
* setup the compression here, so we'll do it only once
*/
switch($this->getType()) {
+
case 'image/png':
$quality = get_config('system', 'png_quality');
if((! $quality) || ($quality > 9))
@@ -73,11 +71,21 @@ class PhotoImagick extends PhotoDriver {
$quality = $quality * 10;
$this->image->setCompressionQuality($quality);
break;
+
case 'image/jpeg':
$quality = get_config('system', 'jpeg_quality');
if((! $quality) || ($quality > 100))
$quality = JPEG_QUALITY;
$this->image->setCompressionQuality($quality);
+ break;
+
+ case 'image/webp':
+ $quality = get_config('system', 'webp_quality');
+ if((! $quality) || ($quality > 100))
+ $quality = WEBP_QUALITY;
+ $this->image->setCompressionQuality($quality);
+ break;
+
default:
break;
}
diff --git a/Zotlabs/Storage/File.php b/Zotlabs/Storage/File.php
index 4610aceb7..36aff1e05 100644
--- a/Zotlabs/Storage/File.php
+++ b/Zotlabs/Storage/File.php
@@ -169,7 +169,7 @@ class File extends DAV\Node implements DAV\IFile {
}
$gis = @getimagesize($f);
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;
}
diff --git a/boot.php b/boot.php
index bc1e2a319..c98ab007d 100755
--- a/boot.php
+++ b/boot.php
@@ -105,6 +105,11 @@ define ( 'JPEG_QUALITY', 100 );
define ( 'PNG_QUALITY', 8 );
/**
+ * App::$config['system']['webp_quality'] from 1 (maximum compressed) to 100 (uncompressed)
+ */
+define ( 'WEBP_QUALITY', 80 );
+
+/**
* Language detection parameters
*/
define ( 'LANGUAGE_DETECT_MIN_LENGTH', 128 );
@@ -899,11 +904,12 @@ class App {
// Serve raw files from the file system in certain cases.
$filext = pathinfo(self::$cmd, PATHINFO_EXTENSION);
- $serve_rawfiles=[
+ $serve_rawfiles = [
'jpg'=>'image/jpeg',
'jpeg'=>'image/jpeg',
'gif'=>'image/gif',
'png'=>'image/png',
+ 'webp'=>'image/webp',
'ico'=>'image/vnd.microsoft.icon',
'css'=>'text/css',
'js'=>'text/javascript',
@@ -913,7 +919,8 @@ class App {
'ttf'=>'font/ttf',
'woff'=>'font/woff',
'woff2'=>'font/woff2',
- 'svg'=>'image/svg+xml'];
+ 'svg'=>'image/svg+xml'
+ ];
if (array_key_exists($filext, $serve_rawfiles) && file_exists(self::$cmd)) {
$staticfilecwd = getcwd();
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',