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

quick hack to eliminate thumbnail image jaggies (libgd req)

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #31  
Old 10-24-2005, 05:34 AM
 
golfguy golfguy is offline
 

Senior Member
  
Join Date: Apr 2005
Location: Omaha,NE
Posts: 108
 

Default

I thought I had it, but I was wrong.

The product_modify.php works like a champ. The thumb_path field of xcart_thumbnails is being populated when I add a new product.

The problem is the test to display the "mini" always fails. in product_thumbnail.tpl


Code:
{if $thumb ne ""}[img]{$thumb}[/img] {else} {if $config.Appearance.show_thumbnails eq "Y"}[img]{if $tmbn_url}{$tmbn_url}{else}{if $full_url}{$http_location}{else}{$xcart_web_dir}{/if}/image.php?productid={$productid}{if $file_upload_data.file_path}&tmp=y{/if}{/if}[/img]{/if} {/if}

$thumb is always equal to "" even though the database is populated.

Did I do somthing wrong in products.tpl?

__________________
Version 4.2.3
Reply With Quote
  #32  
Old 10-24-2005, 06:10 AM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

More than likely this is because the new added function isn't being called where it needs to be. If your wanting in on the category or products listing page, make sure in include/func.php the function func_search_products(); looks like:
Code:
# # Get thumbnail's URL (uses only if images stored in FS) # $result[$key]["tmbn_url"] = func_get_thumbnail_url($result[$key]["productid"]); $result[$key]["thumb"] = func_get_thumbnail_url_($result[$key]["productid"]);

Note the second function call with $result[$key]["thumb"] = func_get_thumbnail_url_(); This is what is passing the value onto the results of $smarty to be used in the template.

There are other parts of X-Cart you may have to search on to find func_get_thumbnail_url and add a new line directly under them with the same values, except, call the new function with the trailing "_" (underscore) and make sure the result array is named "thumb" instead of "tmbn_url".

Some of the other places this call happens is in include/search.php, and even in the upselling and related modules.

I also have convient way to debug templates on my blog, that may help you locate if the variable "thumb" is being populated correctly.

hope this helps.
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #33  
Old 10-24-2005, 07:00 AM
 
golfguy golfguy is offline
 

Senior Member
  
Join Date: Apr 2005
Location: Omaha,NE
Posts: 108
 

Default

Boomer, You da man!

I was missing the call to func_get_thumbnail_url_ in search.php.

Thanks for sharing and helping me implement your mod.
__________________
Version 4.2.3
Reply With Quote
  #34  
Old 10-24-2005, 07:05 AM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

Quote:
Originally Posted by golfguy
Boomer, You da man!

I was missing the call to func_get_thumbnail_url_ in search.php.

Thanks for sharing and helping me implement your mod.

Not a problem, I appreciate you going through and making sure the posted code was in working condition. I was just posting it from previous code and wasn't sure if I was missing anything.

Take a peek at websiteoptimization.com and you can see the difference of download times with smaller thumbnails implemented vs resizing large product thumbnails in html. Defiantly should be standard in X-Cart if you ask me.
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #35  
Old 10-24-2005, 11:56 AM
 
creative xpress creative xpress is offline
 

Advanced Member
  
Join Date: Aug 2005
Posts: 71
 

Default

Ok I have this so close to working but I still have one small problem. It is now creating the thumbnail in the directory and it is referencing it in the db. However I am still getting the resized full res image on the thumbnail page, but I am now getting the resized mini image on the product details page. I have gone back and checked and double checked the code changes and I just cant seem to find my mistake and how these got switched. any ideas?

Thanks!
Cameron
__________________
Xcart
Version: 4.1.6
Reply With Quote
  #36  
Old 10-24-2005, 12:56 PM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

Make sure your skin1/customer/main/product.tpl is using the default out of box {include} for the product_thumbnail.tpl file.

You'll need to add the custom one to the products.tpl and products_t.tpl if your using multi-columns.

You'll also need to adjust the {include} in some of the modules as well, like up selling, etc.
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #37  
Old 10-24-2005, 01:12 PM
 
creative xpress creative xpress is offline
 

Advanced Member
  
Join Date: Aug 2005
Posts: 71
 

Default

Ok I have got it to function properly, however I have one more question. It appears as though the thumbnails that it is creating are very low quality, very jagged and generally poor. Is there a way to increase the quality a bit?
__________________
Xcart
Version: 4.1.6
Reply With Quote
  #38  
Old 10-24-2005, 01:29 PM
 
mffowler mffowler is offline
 

X-Adept
  
Join Date: Mar 2003
Location: Melbourne, Australia
Posts: 811
 

Default

What you need to apply is an unsharp mask, like the Unsharp mask algorithm by Torstein Hц╦nsi. This is what vBulletin uses and the code basically looks like:
Code:
//////////////////////////////////////////////////////////////////////////////////////////////// //// //// p h p U n s h a r p M a s k //// //// Unsharp mask algorithm by Torstein Hц╦nsi 2003. //// thoensi@netcom.no //// Please leave this notice. //// /////////////////////////////////////////////////////////////////////////////////////////////// function UnsharpMask(&$img, $amount = 100, $radius = .5, $threshold = 3) { // $img is an image that is already created within php using // imgcreatetruecolor. No url! $img must be a truecolor image. // Attempt to calibrate the parameters to Photoshop: if ($amount > 500) { $amount = 500; } $amount = $amount * 0.016; if ($radius > 50) { $radius = 50; } $radius = $radius * 2; if ($threshold > 255) { $threshold = 255; } $radius = abs(round($radius)); // Only integers make sense. if ($radius == 0) { return true; } $w = imagesx($img); $h = imagesy($img); $imgCanvas = imagecreatetruecolor($w, $h); $imgCanvas2 = imagecreatetruecolor($w, $h); $imgBlur = imagecreatetruecolor($w, $h); $imgBlur2 = imagecreatetruecolor($w, $h); imagecopy ($imgCanvas, $img, 0, 0, 0, 0, $w, $h); imagecopy ($imgCanvas2, $img, 0, 0, 0, 0, $w, $h); // Gaussian blur matrix: // // 1 2 1 // 2 4 2 // 1 2 1 // ////////////////////////////////////////////////// // Move copies of the image around one pixel at the time and merge them with weight // according to the matrix. The same matrix is simply repeated for higher radii. for ($i = 0; $i < $radius; $i++) { imagecopy ($imgBlur, $imgCanvas, 0, 0, 1, 1, $w - 1, $h - 1); // up left imagecopymerge ($imgBlur, $imgCanvas, 1, 1, 0, 0, $w, $h, 50); // down right imagecopymerge ($imgBlur, $imgCanvas, 0, 1, 1, 0, $w - 1, $h, 33.33333); // down left imagecopymerge ($imgBlur, $imgCanvas, 1, 0, 0, 1, $w, $h - 1, 25); // up right imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 1, 0, $w - 1, $h, 33.33333); // left imagecopymerge ($imgBlur, $imgCanvas, 1, 0, 0, 0, $w, $h, 25); // right imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 20 ); // up imagecopymerge ($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 16.666667); // down imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 0, 0, $w, $h, 50); // center imagecopy ($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h); // During the loop above the blurred copy darkens, possibly due to a roundoff // error. Therefore the sharp picture has to go through the same loop to // produce a similar image for comparison. This is not a good thing, as processing // time increases heavily. imagecopy ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 20 ); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 16.666667); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50); imagecopy ($imgCanvas2, $imgBlur2, 0, 0, 0, 0, $w, $h); } imagedestroy($imgBlur); imagedestroy($imgBlur2); // Calculate the difference between the blurred pixels and the original // and set the pixels for ($x = 0; $x < $w; $x++) { // each row for ($y = 0; $y < $h; $y++) { // each pixel $rgbOrig = ImageColorAt($imgCanvas2, $x, $y); $rOrig = (($rgbOrig >> 16) & 0xFF); $gOrig = (($rgbOrig >> 8) & 0xFF); $bOrig = ($rgbOrig & 0xFF); $rgbBlur = ImageColorAt($imgCanvas, $x, $y); $rBlur = (($rgbBlur >> 16) & 0xFF); $gBlur = (($rgbBlur >> 8) & 0xFF); $bBlur = ($rgbBlur & 0xFF); // When the masked pixels differ less from the original // than the threshold specifies, they are set to their original value. $rNew = (abs($rOrig - $rBlur) >= $threshold) ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) : $rOrig; $gNew = (abs($gOrig - $gBlur) >= $threshold) ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) : $gOrig; $bNew = (abs($bOrig - $bBlur) >= $threshold) ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) : $bOrig; $pixCol = imagecolorallocate ($img, $rNew, $gNew, $bNew); imagesetpixel ($img, $x, $y, $pixCol); } } imagedestroy($imgCanvas); imagedestroy($imgCanvas2); return true; }
If you have a copy of vBulletin- see how it works in functions_image.php as that is basically what Boomer is doing.

Boomer- ever used this?

- Mike
__________________
4.1.9
Reply With Quote
  #39  
Old 10-24-2005, 01:42 PM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

in product_modify.php

try swapping the comment out on this code:
Code:
#ImageAlphaBlending($photoImage, true); ImageAntiAlias($photoImage, true);

As I've noticed some GD libraries will use the later of the two when anti-aliasing a rescaled image.
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #40  
Old 10-24-2005, 02:50 PM
 
creative xpress creative xpress is offline
 

Advanced Member
  
Join Date: Aug 2005
Posts: 71
 

Default

Boomer that change did not make a difference in the quality. I am not sure how to go about implementing the code from mffowler. I do know that my hair is getting thinner!!!



Thanks again for all your help!
Cameron
__________________
Xcart
Version: 4.1.6
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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 10:33 PM.

   

 
X-Cart forums © 2001-2020