Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Detailed Product Images Module - Changing Unsharp Mask Filter Parameters
 
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features
 
Thread Tools Search this Thread
  #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:	91
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

The following 6 users thank ADDISON for this useful post:
cflsystems (04-12-2012), cherie (12-31-2010), parekh81 (01-27-2011), qualiteam (04-12-2012), rocky (04-11-2012), thebluedoorboutique (04-13-2012)
  #2  
Old 04-11-2012, 11:56 PM
  rocky's Avatar 
rocky rocky is offline
 

X-Cart team
  
Join Date: Jul 2005
Posts: 715
 

Default 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
__________________
Alexander Diatchkov
Head of Technical Support Department

Official X-Cart Support at:
http://www.x-cart.com/technical-support.html
Reply With Quote
  #3  
Old 04-13-2012, 06:31 AM
 
thebluedoorboutique thebluedoorboutique is offline
 

Senior Member
  
Join Date: May 2011
Posts: 124
 

Default 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!
__________________
X-Cart Classic 4.4.X
Reply With Quote
  #4  
Old 06-08-2012, 09:55 AM
  ADDISON's Avatar 
ADDISON ADDISON is offline
 

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

Lightbulb 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

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.
__________________
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
  #5  
Old 06-09-2012, 05:40 AM
  ADDISON's Avatar 
ADDISON ADDISON is offline
 

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

Default 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.
__________________
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
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

   

 
X-Cart forums © 2001-2018