Support WEBP images in mail messages (#5362)

pull/321/merge
Aleksander Machniak 8 years ago
parent 1988f68660
commit 7a7a6795f0

@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================
- Support WEBP images in mail messages (#5362)
- Support MathML in HTML message preview (#5182)
- Rename Addressbook to Contacts (#5233)
- Remove PHP mail() support, smtp_server is required now (#5340)

@ -8850,7 +8850,7 @@ function rcube_webmail()
if (!this.env.browser_capabilities)
this.env.browser_capabilities = {};
$.each(['pdf', 'flash', 'tif'], function() {
$.each(['pdf', 'flash', 'tiff', 'webp'], function() {
if (ref.env.browser_capabilities[this] === undefined)
ref.env.browser_capabilities[this] = ref[this + '_support_check']();
});
@ -8870,16 +8870,26 @@ function rcube_webmail()
return ret.join();
};
this.tif_support_check = function()
this.tiff_support_check = function()
{
this.image_support_check('tiff');
return 0;
};
this.webp_support_check = function()
{
this.image_support_check('webp');
return 0;
};
this.image_support_check = function(type)
{
window.setTimeout(function() {
var img = new Image();
img.onload = function() { ref.env.browser_capabilities.tif = 1; };
img.onerror = function() { ref.env.browser_capabilities.tif = 0; };
img.src = ref.assets_path('program/resources/blank.tif');
img.onload = function() { ref.env.browser_capabilities[type] = 1; };
img.onerror = function() { ref.env.browser_capabilities[type] = 0; };
img.src = ref.assets_path('program/resources/blank.' + type);
}, 10);
return 0;
};
this.pdf_support_check = function()

@ -393,7 +393,9 @@ class rcube_config
}
else if ($name == 'client_mimetypes') {
if (!$result && !$def) {
$result = 'text/plain,text/html,text/xml,image/jpeg,image/gif,image/png,image/bmp,image/tiff,application/x-javascript,application/pdf,application/x-shockwave-flash';
$result = 'text/plain,text/html,text/xml'
. ',image/jpeg,image/gif,image/png,image/bmp,image/tiff,image/webp'
. ',application/x-javascript,application/pdf,application/x-shockwave-flash';
}
if ($result && is_string($result)) {
$result = explode(',', $result);

@ -62,8 +62,8 @@ class rcube_image
if (function_exists('getimagesize') && ($imsize = @getimagesize($this->image_file))) {
$width = $imsize[0];
$height = $imsize[1];
$gd_type = $imsize['2'];
$type = image_type_to_extension($imsize['2'], false);
$gd_type = $imsize[2];
$type = image_type_to_extension($gd_type, false);
$channels = $imsize['channels'];
}
@ -166,7 +166,7 @@ class rcube_image
else {
try {
$image = new Imagick($this->image_file);
$image->setImageBackgroundColor('white');
$image->setImageAlphaChannel(11);
$image->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
@ -205,11 +205,11 @@ class rcube_image
$image = imagecreatefromjpeg($this->image_file);
$type = 'jpg';
}
else if($props['gd_type'] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) {
else if ($props['gd_type'] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) {
$image = imagecreatefromgif($this->image_file);
$type = 'gif';
}
else if($props['gd_type'] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')) {
else if ($props['gd_type'] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')) {
$image = imagecreatefrompng($this->image_file);
$type = 'png';
}
@ -354,7 +354,6 @@ class rcube_image
return false;
}
if ($props['gd_type']) {
if ($props['gd_type'] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) {
$image = imagecreatefromjpeg($this->image_file);

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 B

@ -1369,17 +1369,22 @@ function rcmail_message_body($attrib)
function rcmail_part_image_type($part)
{
// Skip TIFF images if browser doesn't support this format...
$tiff_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['tif']);
// until we can convert them to JPEG
$mimetype = strtolower($part->mimetype);
// Skip TIFF/WEBP images if browser doesn't support this format
// ...until we can convert them to JPEG
$tiff_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['tiff']);
$tiff_support = $tiff_support || rcube_image::is_convertable('image/tiff');
$webp_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['webp']);
$webp_support = $webp_support || rcube_image::is_convertable('image/webp');
// Content-type regexp
$mime_regex = $tiff_support ? '/^image\//i' : '/^image\/(?!tif)/i';
if ((!$tiff_support && $mimetype == 'image/tiff') || (!$webp_support && $mimetype == 'image/webp')) {
return;
}
// Content-Type: image/*...
if (preg_match($mime_regex, $part->mimetype)) {
return rcmail_fix_mimetype($part->mimetype);
if (strpos($mimetype, 'image/') === 0) {
return rcmail_fix_mimetype($mimetype);
}
// Many clients use application/octet-stream, we'll detect mimetype
@ -1397,9 +1402,12 @@ function rcmail_part_image_type($part)
$types['tif'] = 'image/tiff';
$types['tiff'] = 'image/tiff';
}
if ($webp_support) {
$types['webp'] = 'image/webp';
}
if ($part->filename
&& preg_match('/^application\/octet-stream$/i', $part->mimetype)
&& $mimetype == 'application/octet-stream'
&& preg_match('/\.([^.]+)$/i', $part->filename, $m)
&& ($extension = strtolower($m[1]))
&& isset($types[$extension])

@ -238,14 +238,17 @@ else if (strlen($part_id)) {
}
// TIFF to JPEG conversion, if needed
$tiff_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['tif']);
if (!empty($_REQUEST['_embed']) && !$tiff_support
&& rcube_image::is_convertable('image/tiff')
&& rcmail_part_image_type($part) == 'image/tiff'
) {
$tiff2jpeg = true;
$mimetype = 'image/jpeg';
// TIFF/WEBP to JPEG conversion, if needed
foreach (array('tiff', 'webp') as $type) {
$img_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps'][$type]);
if (!empty($_REQUEST['_embed']) && !$img_support
&& rcmail_part_image_type($part) == 'image/' . $type
&& rcube_image::is_convertable('image/' . $type)
) {
$convert2jpeg = true;
$mimetype = 'image/jpeg';
break;
}
}
@ -335,7 +338,7 @@ else if (strlen($part_id)) {
header("Content-Disposition: $disposition; filename=\"$filename\"");
// handle tiff to jpeg conversion
if (!empty($tiff2jpeg)) {
if (!empty($convert2jpeg)) {
$temp_dir = unslashify($RCMAIL->config->get('temp_dir'));
$file_path = tempnam($temp_dir, 'rcmAttmnt');

@ -102,10 +102,12 @@ if ($uid) {
if (empty($_SESSION['browser_caps']['flash']) && ($key = array_search('application/x-shockwave-flash', $mimetypes)) !== false) {
unset($mimetypes[$key]);
}
if (empty($_SESSION['browser_caps']['tif']) && ($key = array_search('image/tiff', $mimetypes)) !== false) {
// we can convert tiff to jpeg
if (!rcube_image::is_convertable('image/tiff')) {
unset($mimetypes[$key]);
foreach (array('tiff', 'webp') as $type) {
if (empty($_SESSION['browser_caps'][$type]) && ($key = array_search('image/' . $type, $mimetypes)) !== false) {
// can we convert it to jpeg?
if (!rcube_image::is_convertable('image/' . $type)) {
unset($mimetypes[$key]);
}
}
}
if (!in_array('message/rfc822', $mimetypes)) {

Loading…
Cancel
Save