Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Core/Controller/EditSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ protected function loadData($viewName, $view)
if ($view->model instanceof Settings && empty($view->model->name)) {
$view->model->name = $code;
}
if ($view->model instanceof Settings && empty($view->model->image_compression)) {
$view->model->image_compression = 'medium';
}
$this->loadPaymentMethodValues($viewName);
$this->loadWarehouseValues($viewName);
$this->loadLogoImageValues($viewName);
Expand Down
48 changes: 45 additions & 3 deletions Core/Model/AttachedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ protected function stripImageMetadata(string $filePath, string $mimeType): void
case 'image/jpeg':
$image = @imagecreatefromjpeg($filePath);
if ($image) {
imagejpeg($image, $filePath, 95);
imagejpeg($image, $filePath, $this->getJpegQuality());
}
break;

Expand All @@ -337,7 +337,7 @@ protected function stripImageMetadata(string $filePath, string $mimeType): void
if ($image) {
imagealphablending($image, false);
imagesavealpha($image, true);
imagepng($image, $filePath, 6);
imagepng($image, $filePath, $this->getPngQuality(), PNG_ALL_FILTERS);
}
break;

Expand All @@ -349,9 +349,51 @@ protected function stripImageMetadata(string $filePath, string $mimeType): void
if ($image) {
imagealphablending($image, false);
imagesavealpha($image, true);
imagewebp($image, $filePath, 95);
imagewebp($image, $filePath, $this->getWebpQuality());
}
break;
}
}

protected function getJpegQuality(): int
{
switch (Tools::settings('default', 'image_compression', 'medium')) {
case 'low':
return 95;

case 'high':
return 75;

default:
return 90;
}
}

protected function getWebpQuality(): int
{
switch (Tools::settings('default', 'image_compression', 'medium')) {
case 'low':
return IMG_WEBP_LOSSLESS;

case 'high':
return 75;

default:
return 90;
}
}

protected function getPngQuality(): int
{
switch (Tools::settings('default', 'image_compression', 'medium')) {
case 'low':
return 1;

case 'high':
return 9;

default:
return 6;
}
}
}
3 changes: 3 additions & 0 deletions Core/Translation/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@
"idaccount": "Id. Cuenta",
"idem-wildcard-info": "Copiar el valor de la linea anterior",
"image": "Imagen",
"image-compression": "Compresión de imágenes",
"images": "Imágenes",
"images-added-correctly": "%count% imágenes añadidas correctamente",
"imp-surcharge": "Imp. recargo",
Expand Down Expand Up @@ -1103,6 +1104,7 @@
"longnumero-must-be-between-1-and-10": "La longitud del número debe estar entre 1 y 10",
"look-for-gaps": "Buscar huecos",
"lot": "Lote",
"low": "Bajo",
"low-security": "Baja seguridad",
"machine": "Máquina",
"machines": "Máquinas",
Expand Down Expand Up @@ -1133,6 +1135,7 @@
"maximum-stock": "Stock máximo",
"may": "Mayo",
"media-whatsapp-not-upload": "Error al subir el archivo multimedia al servidor de WhatsApp: %file%",
"medium": "Medio",
"mega-search": "MegaBuscador",
"memcache": "Memcache",
"memcache-clear": "Memcache limpiada.",
Expand Down
7 changes: 7 additions & 0 deletions Core/XMLView/SettingsDefault.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@
<widget type="library" fieldname="idloginimage" icon="fa-solid fa-image" onclick="EditAttachedFile"
accept=".gif,.jpg,.jpeg,.png,.webp"/>
</column>
<column name="image-compression" numcolumns="3" order="125">
<widget type="select" fieldname="image_compression" icon="fa-solid fa-compress" required="true" translate="true">
<values title="low">low</values>
<values title="medium">medium</values>
<values title="high">high</values>
</widget>
</column>
<column name="table-size" numcolumns="3" order="130">
<widget type="select" fieldname="tablesize" icon="fa-solid fa-table" required="true" translate="true">
<values title="big">big</values>
Expand Down
Loading