2
0
forked from Wavyzz/dolibarr

Fix webp support

This commit is contained in:
Laurent Destailleur
2020-06-03 14:05:18 +02:00
parent 8023bc2fbb
commit 7b84518e59
4 changed files with 31 additions and 8 deletions

View File

@@ -880,12 +880,13 @@ function newpopup(url, title) {
*/
function document_preview(file, type, title)
{
var ValidImageTypes = ["image/gif", "image/jpeg", "image/png"];
var ValidImageTypes = ["image/gif", "image/jpeg", "image/png", "image/webp"];
var showOriginalSizeButton = false;
console.log("document_preview A click was done. file="+file+", type="+type+", title="+title);
if ($.inArray(type, ValidImageTypes) < 0) {
/* Not an image */
var width='85%';
var object_width='100%';
var height = ($( window ).height() - 60) * 0.90;
@@ -894,6 +895,7 @@ function document_preview(file, type, title)
show_preview('notimage');
} else {
/* This is an image */
var object_width=0;
var object_height=0;
@@ -904,11 +906,13 @@ function document_preview(file, type, title)
object_height = this.height;
width = $( window ).width()*0.90;
console.log("object_width="+object_width+" window width="+width);
if(object_width < width){
console.log("Object width is small, we set width of popup according to image width.");
width = object_width + 30
}
height = $( window ).height()*0.85;
console.log("object_height="+object_height+" window height="+height);
if(object_height < height){
console.log("Object height is small, we set height of popup according to image height.");
height = object_height + 80

View File

@@ -8055,7 +8055,7 @@ function getImageFileNameForSize($file, $extName, $extImgTarget = '')
$dirName = dirname($file);
if ($dirName == '.') $dirName = '';
$fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i', '', $file); // We remove extension, whatever is its case
$fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp|\.webp)$/i', '', $file); // We remove extension, whatever is its case
$fileName = basename($fileName);
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
@@ -8063,6 +8063,7 @@ function getImageFileNameForSize($file, $extName, $extImgTarget = '')
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.webp$/i', $file) ? '.webp' : '');
if (!$extImgTarget) return $file;
@@ -8088,7 +8089,7 @@ function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata = 0, $param
if (empty($conf->use_javascript_ajax)) return '';
$mime_preview = array('bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css', 'svg+xml');
$mime_preview = array('bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css', 'svg+xml', 'webp');
//$mime_preview[]='vnd.oasis.opendocument.presentation';
//$mime_preview[]='archive';
$num_mime = array_search(dol_mimetype($relativepath, '', 1), $mime_preview);
@@ -8199,6 +8200,7 @@ function dol_mimetype($file, $default = 'application/octet-stream', $mode = 0)
if (preg_match('/\.bmp$/i', $tmpfile)) { $mime = 'image/bmp'; $imgmime = 'image.png'; $famime = 'file-image-o'; }
if (preg_match('/\.(tif|tiff)$/i', $tmpfile)) { $mime = 'image/tiff'; $imgmime = 'image.png'; $famime = 'file-image-o'; }
if (preg_match('/\.svg$/i', $tmpfile)) { $mime = 'image/svg+xml'; $imgmime = 'image.png'; $famime = 'file-image-o'; }
if (preg_match('/\.webp$/i', $tmpfile)) { $mime = 'image/webp'; $imgmime = 'image.png'; $famime = 'file-image-o'; }
// Calendar
if (preg_match('/\.vcs$/i', $tmpfile)) { $mime = 'text/calendar'; $imgmime = 'other.png'; $famime = 'file-text-o'; }
if (preg_match('/\.ics$/i', $tmpfile)) { $mime = 'text/calendar'; $imgmime = 'other.png'; $famime = 'file-text-o'; }

View File

@@ -37,7 +37,7 @@ $quality = 80;
*/
function image_format_supported($file)
{
$regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.xpm|\.xbm|\.svg'; // See also into product.class.php
$regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm|\.svg'; // See also into product.class.php
// Case filename is not a format image
$reg = array();
@@ -46,10 +46,11 @@ function image_format_supported($file)
// Case filename is a format image but not supported by this PHP
$imgfonction = '';
if (strtolower($reg[1]) == '.gif') $imgfonction = 'imagecreatefromgif';
if (strtolower($reg[1]) == '.png') $imgfonction = 'imagecreatefrompng';
if (strtolower($reg[1]) == '.jpg') $imgfonction = 'imagecreatefromjpeg';
if (strtolower($reg[1]) == '.jpeg') $imgfonction = 'imagecreatefromjpeg';
if (strtolower($reg[1]) == '.png') $imgfonction = 'imagecreatefrompng';
if (strtolower($reg[1]) == '.bmp') $imgfonction = 'imagecreatefromwbmp';
if (strtolower($reg[1]) == '.webp') $imgfonction = 'imagecreatefromwebp';
if (strtolower($reg[1]) == '.xpm') $imgfonction = 'imagecreatefromxpm';
if (strtolower($reg[1]) == '.xbm') $imgfonction = 'imagecreatefromxbm';
if (strtolower($reg[1]) == '.svg') $imgfonction = 'imagecreatefromsvg'; // Never available
@@ -60,10 +61,12 @@ function image_format_supported($file)
// Fonctions of conversion not available in this PHP
return 0;
}
}
// Filename is a format image and supported for conversion by this PHP
return 1;
}
return 0;
}
@@ -180,6 +183,9 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
case 4: // IMG_WBMP
$imgfonction = 'imagecreatefromwbmp';
break;
case 17: // IMG_WBMP
$imgfonction = 'imagecreatefromwebp';
break;
}
if ($imgfonction)
{
@@ -213,6 +219,11 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
$extImg = '.bmp';
$newquality = 'NU'; // Quality is not used for this format
break;
case 18: // Webp
$img = imagecreatefromwebp($filetoread);
$extImg = '.webp';
$newquality = '100'; // % quality maximum
break;
}
// Create empty image
@@ -255,6 +266,9 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
case 4: // Bmp
$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
break;
case 18: // Webp
$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127);
break;
}
if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour);
@@ -283,6 +297,9 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
case 4: // Bmp
imagewbmp($imgThumb, $imgThumbName);
break;
case 18: // Webp
imagewebp($imgThumb, $imgThumbName, $newquality);
break;
}
// Set permissions on file

View File

@@ -79,7 +79,7 @@ class Product extends CommonObject
*/
protected $table_ref_field = 'ref';
public $regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.xpm|\.xbm'; // See also into images.lib.php
public $regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm'; // See also into images.lib.php
/*
* @deprecated