View Single Post
  #1  
Old 12-31-2010, 05:47 AM
  ADDISON's Avatar 
ADDISON ADDISON is offline
 

X-Man
  
Join Date: Jan 2008
Posts: 2,613
 

Default Detailed Product Images Module - Changing Unsharp Mask Filter Parameters

By default Unsharp Mask Filter parameters are: Amount = 120, Radius = 0.4, Threshold = 1. Parameters are stored here: [X-Cart_DIR]/include/lib/phpunsharpmask.php

Maybe some of you are not happy with these values because the resized images look bad. No problem you can change the parameters in line 28: function UnsharpMask($img, $amount = 120, $radius = 0.4, $threshold = 1). I am one who did not like this approach, editing a php file. I requested many times after v4.2 was released, to set up the parameters in Admin. Having no solutions, I did it myself and I would like to share with you this. It is an elegant way, and hope QT to insert it by default in the next XC versions.

We will insert Amount, Radius, Threshold in Admin -> Detailed Product Images Module.

1) Delete default values in phpunsharmask.php file

- go to: [X-Cart_Dir]/include/lib/phpunsharpmask.php
- line 28

original: function UnsharpMask($img, $amount = 120, $radius = 0.4, $threshold = 1)

modify: function UnsharpMask($img, $amount, $radius, $threshold)

2) Call parameters in func.images.php

- go to: [X-Cart_Dir]/include/func/func_image.php
- line 1143

original: if (function_exists('UnsharpMask')) $_image = UnsharpMask($new_image);

modify: if (function_exists('UnsharpMask'))
{
$amount = $config['Detailed_Product_Images']['det_unsharpmask_amount'];
$radius = $config['Detailed_Product_Images']['det_unsharpmask_radius'];
$threshold = $config['Detailed_Product_Images']['det_unsharpmask_threshold'];
$_image = UnsharpMask($new_image, $amount, $radius, $threshold);
}

3) Adding parameters values in database

Execute these SQL queries:

INSERT INTO `xcart_config` VALUES ('det_unsharpmask_amount', 'Unsharp mask - Amount', '120', 'Detailed_Product_Images', 60, 'numeric', '120', '', '');
INSERT INTO `xcart_config` VALUES ('det_unsharpmask_radius', 'Unsharp mask - Radius', '0.4', 'Detailed_Product_Images', 61, 'numeric', '0.4', '', '');
INSERT INTO `xcart_config` VALUES ('det_unsharpmask_threshold', 'Unsharp mask - Threshold', '1', 'Detailed_Product_Images', 62, 'numeric', '1', '', '');

4) Adding language labels for parameters values in database

Execute these SQL queries:

INSERT INTO `xcart_languages` VALUES ('en', 'opt_det_unsharpmask_amount', 'Unsharp Mask - Amount', 'Options');
INSERT INTO `xcart_languages` VALUES ('en', 'opt_det_unsharpmask_radius', 'Unsharp Mask - Radius', 'Options');
INSERT INTO `xcart_languages` VALUES ('en', 'opt_det_unsharpmask_threshold', 'Unsharp Mask - Threshold', 'Options');

Now you can change Unsharp Mark Filter parameters in Detailed Product Images Module and forget about editing php files. I did not know how to update all images in cache, after changing a parameter value. That's why I recommended after changing parameters to modify one of the maximum size of an image to get the new results. Hope with your contribution to do this also.

Happy New Year!
Attached Thumbnails
Click image for larger version

Name:	unsharp_mask.jpg
Views:	265
Size:	106.0 KB
ID:	2269  
__________________
X-Cart Next: Business 5.2 (learning and testing)
X-Cart Classic: Gold and Gold Plus 4.7
Lots of Modules and Customizations
OS in use: Red Hat Enterprise, Fedora, CentOS, Debian, Ubuntu, Linux Mint, Kali Linux
Ideas for Server configuration (basicaly): Nginx/Pound (reverse proxy), Apache/Nginx (webserver), Squid/Varnish (cache server), HHVM or (PHP-FPM + PHP 5.6 + opcache), MariaDB/Percona MySQL Server, Redis (storing sessions)

You can catch my ideas here: http://ideas.x-cart.com
Reply With Quote