Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #475, reduce reprocessed jpeg image file size by defaulting image quality to 85% #2629

Merged
merged 5 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 9 additions & 4 deletions app/code/core/Mage/Core/Model/File/Validator/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function setAllowedImageTypes(array $imageFileExtensions = [])
}

/**
* Validation callback for checking is file is image
* Validation callback for checking if file is image
*
* @param string $filePath Path to temporary uploaded file
* @return null
Expand All @@ -85,8 +85,13 @@ public function validate($filePath)
list($imageWidth, $imageHeight, $fileType) = getimagesize($filePath);
if ($fileType) {
if ($this->isImageType($fileType)) {
/** if 'general/reprocess_images/active' false then skip image reprocessing. */
if (!Mage::getStoreConfigFlag('general/reprocess_images/active')) {
/** Check deprecated 'general/reprocess_images/active' for BC. If false then skip image reprocessing. */
if (Mage::getStoreConfig('general/reprocess_images/active') !== null) {
$imageQuality = Mage::getStoreConfigFlag('general/reprocess_images/active') ? 100 : 0;
elidrissidev marked this conversation as resolved.
Show resolved Hide resolved
kiatng marked this conversation as resolved.
Show resolved Hide resolved
} else {
$imageQuality = (int) Mage::getStoreConfig('admin/security/reprocess_image_quality');
}
if ($imageQuality === 0) {
return null;
}
//replace tmp image with re-sampled copy to exclude images with malicious data
Expand Down Expand Up @@ -116,7 +121,7 @@ public function validate($filePath)
imagegif($img, $filePath);
break;
case IMAGETYPE_JPEG:
imagejpeg($img, $filePath, 100);
imagejpeg($img, $filePath, $imageQuality);
break;
case IMAGETYPE_PNG:
imagepng($img, $filePath);
Expand Down
5 changes: 1 addition & 4 deletions app/code/core/Mage/Core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@
<extensions_compatibility_mode>1</extensions_compatibility_mode>
<session_cookie_lifetime>10800</session_cookie_lifetime>
<secure_system_configuration_save_disabled>0</secure_system_configuration_save_disabled>
<reprocess_image_quality>85</reprocess_image_quality>
</security>
</admin>
<general>
Expand Down Expand Up @@ -497,10 +498,6 @@
</protected>
</public_files_valid_paths>
</file>
<!-- NOTE: If you turn off images reprocessing, then your upload images process may cause security risks. -->
<reprocess_images>
<active>1</active>
</reprocess_images>
<!-- Additional email for notifications -->
<additional_notification_emails>
<!-- On creating a new admin user. You can specify several emails separated by commas. -->
Expand Down
9 changes: 9 additions & 0 deletions app/code/core/Mage/Core/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,15 @@
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
</crate_admin_user_notification>
<reprocess_image_quality translate="label comment">
<label>Image Reprocess Quality</label>
<comment>Optimum value is 85, higher value will increase file size. Set to 0 to turn off images reprocessing, which may cause security risks.</comment>
<validate>required-entry validate-digits validate-digits-range digits-range-0-100</validate>
<sort_order>180</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</reprocess_image_quality>
</fields>
</security>
<dashboard translate="label">
Expand Down
2 changes: 2 additions & 0 deletions app/locale/en_US/Mage_Core.csv
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"How many links to display at once.","How many links to display at once."
"ID Path for Specified Store","ID Path for Specified Store"
"If the current frame position does not cover utmost pages, will render link to current position plus/minus this value.","If the current frame position does not cover utmost pages, will render link to current position plus/minus this value."
"Image Reprocess Quality","Image Reprocess Quality"
"Incorrect credit card expiration date.","Incorrect credit card expiration date."
"Input type ""%value%"" not found in the input types list.","Input type ""%value%"" not found in the input types list."
"Invalid MIME type.","Invalid MIME type."
Expand Down Expand Up @@ -226,6 +227,7 @@
"New Website","New Website"
"No","No"
"Offloader header","Offloader header"
"Optimum value is 85, higher value will increase file size. Set to 0 to turn off images reprocessing, which may cause security risks.","Optimum value is 85, higher value will increase file size. Set to 0 to turn off images reprocessing, which may cause security risks."
"PHP SOAP extension is required.","PHP SOAP extension is required."
"Package","Package"
"Pagination","Pagination"
Expand Down