X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Detailed Product Images Module - Changing Unsharp Mask Filter Parameters (https://forum.x-cart.com/showthread.php?t=57296)

ADDISON 12-31-2010 05:47 AM

Detailed Product Images Module - Changing Unsharp Mask Filter Parameters
 
1 Attachment(s)
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!

rocky 04-11-2012 11:56 PM

Re: Detailed Product Images Module - Changing Unsharp Mask Filter Parameters
 
Quote:

Originally Posted by am2003
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.


Thank you for the post, much appreciated! I find it very useful and I hope all X-Carters do as well.

We contemplated the idea of adding these parameters to the settings, but then came to a conclusion that they might be confusing and not as informative for the average X-Cart user who is not as experienced in design as you.

However, we are planning to add an article to our online help portal at http://help.x-cart.com/ which describes how to adjust sharpness for the thumbnails

thebluedoorboutique 04-13-2012 06:31 AM

Re: Detailed Product Images Module - Changing Unsharp Mask Filter Parameters
 
My business sales clothes online, so images are everything but I don't know that much about this you're talking about. Can we visually see the difference in images in an example here? Thank for this code!

ADDISON 06-08-2012 09:55 AM

Re: Detailed Product Images Module - Changing Unsharp Mask Filter Parameters
 
Let's update this old thread with automatically re-generation image cache after changing one of the values for Amount, Radius, Threshold 8)

1) Open file: [XC_Dir]/[ADMIN_Dir]/configuration.php

2) Search for the following string: "// Regenerate image cache" (without quotes)

3) After this

PHP Code:

|| $config['Detailed_Product_Images']['det_image_max_height_icon'] != $_POST['det_image_max_height_icon'


4) Paste this

PHP Code:

|| $config['Detailed_Product_Images']['det_unsharpmask_amount'] != $_POST['det_unsharpmask_amount']
|| 
$config['Detailed_Product_Images']['det_unsharpmask_radius'] != $_POST['det_unsharpmask_radius']
|| 
$config['Detailed_Product_Images']['det_unsharpmask_threshold'] != $_POST['det_unsharpmask_radius'


Now change any of the values for Amount, Radius, Threshold and you will get automatically re-generation of your image cache. There is no need to go in Maintenance all the time after changing a value.

After this final step in my humble opinion this should be a "must have" inside the next XC4 version (4.5.1 as well). No more hard coded for unsharp mask values, re-generation, ugly thumbs.

P.S. We should do something with the tabs in product page. No more hard coded there too. Personally I know how to deal with new tabs, sorting, hiding, but how many of us know how to do this? Please take in consideration an elegant way for creating, hiding, arranging tabs in Admin interface (4.5.2). It is not complicated at all guys.

ADDISON 06-09-2012 05:40 AM

Re: Detailed Product Images Module - Changing Unsharp Mask Filter Parameters
 
One more thing, I think admin/configuration.php has some issues with re-generation. This needs an investigation. For example if section is Appearance the results are not the same like section is Tools. Re-generating image cache from Maintenance section never gives problems. But for other sections there are: Detailed Image Product, Appearance. I reported this in Bugtracker.


All times are GMT -8. The time now is 02:10 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.