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
  #21  
Old 10-14-2005, 01:25 PM
  B00MER's Avatar 
B00MER B00MER is offline
 

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

Default

The code I posted from include/product_modify.php has the section of code you'll need to copy into the if ($store_in == "FS") condition and setup accordingly. However most of the code is arleady there just needs to be reconfigured to work properly with importing, etc.

hth.
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #22  
Old 10-15-2005, 02:43 PM
 
golfguy golfguy is offline
 

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

Default

The product_modify.php seems to be working. xcart_thumbnails.thumb_path contains

/home/teststore/domains/teststore.com/public_html/skin1/images/thumb/6.jpg

and I checked with FTP and the file exists, the thumbnal image displays but the larger "thumbnail" on the detail page no longer displays. It's got "little red x" Syndrome

xcart_thumbnails.image_path contains

/home/teststore/domains/teststore.com/public_html/images/t_6.jpg

but the file does not exist

Did I delete something out of product_modify that I shouldn't have?
__________________
Version 4.2.3
Reply With Quote
  #23  
Old 10-16-2005, 05:57 PM
 
golfguy golfguy is offline
 

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

Default

My test store still has the product detail image problem, but I thought I'd pass along a work around to the import problem.

This is based on my decision to name the new "mini" thumbnails the same as the image_path with "_width" as a suffix.

I batch resized my full size images with Fireworks (Photoshop can do this as well) appending "_120" to the file name, and uploaded them to the same place as my other images.

after you have created the thumb_path column, while still in SQL

Code:
update xcart_thumbnails set thumb_path = image_path; update xcart_thumbnails set thumb_path = replace(thumb_path,'.jpg','_120.jpg');
__________________
Version 4.2.3
Reply With Quote
  #24  
Old 10-16-2005, 09:12 PM
  B00MER's Avatar 
B00MER B00MER is offline
 

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

Default

If all you did was copy the commented code and the sql changes at the end of the commented code, should be all you need for both the new and update products sections of the code. Make sure you've got the proper full paths to where you are going to be storing the mini thumbs. It should NOT affect the "Product Detail" thumbnails.
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #25  
Old 10-17-2005, 09:19 AM
 
creative xpress creative xpress is offline
 

Advanced Member
  
Join Date: Aug 2005
Posts: 71
 

Default

I tried the same code from the previous files and now I get an error concerning the fopen, fwrite, fclose, and image destroy. as not a valid stream resource. fopen claims no such file or directory.

Is it possible that it is doing this because I am updating products rather than adding new ones?

Thanks
__________________
Xcart
Version: 4.1.6
Reply With Quote
  #26  
Old 10-17-2005, 10:36 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 the directory you put in for the $handle variable isn't readable or writeable by the web server. Make sure the proper chmod and chown are on the fopen path you specified.

Keep in mind this was code snippet I had laying around from the orginal mod that was written for 3.5.9 and ported to 4.0.x afterwards.

Be sure GD library is installed and enabled. Written with: GD Version bundled (2.0.28 compatible) If you want to find the version or see if its available or enabled: X-Cart admin -> Summary find php and click "details".

Here's a cleaned up version of the product_modify.php file with no watermarking code commented out, may help debugging it easier.

If you need to find if the table is appearing simply put {$thumb} in product_thumbnail.tpl and you should see a full path to the image.
Code:
{if $thumb ne ""}[img]{$thumb}[/img] {else} {* original product_thumbnail.tpl *} {/if}

... And here's product_modify.php:

Code:
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # GD by B00MER (www.cart-lab.com) # # Apply SQL Patch: # ALTER TABLE `xcart_thumbnails` ADD `thumb_path` VARCHAR( 255 ) NOT NULL # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # Generate New thumbnail # get image $photoImage = ImageCreateFromJPEG($image_data["image"]); ImageAlphaBlending($photoImage, true); #ImageAntiAlias($photoImage, true); # get size of original image $size = getimagesize($image_data["image"]); # resize our original image $new_w = 75; $new_h = 75; $old_x=imageSX($photoImage); $old_y=imageSY($photoImage); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } # create image resource and resize $thumb_img = imagecreatetruecolor($thumb_w,$thumb_h); #imagecopyresized($thumb_img, $photoImage, 0,0,0,0, imagesx($thumb_img), imagesy($thumb_img), imagesx($photoImage), imagesy($photoImage)); imagecopyresampled($thumb_img, $photoImage, 0,0,0,0, imagesx($thumb_img), imagesy($thumb_img), imagesx($photoImage), imagesy($photoImage)); # begin output of new thumbnail ob_start(); ImageJPEG($thumb_img,"",90); $thumb_imagedata_ = ob_get_contents(); ob_end_clean(); # write thumbnail to a file $handle = fopen("/home/user/xcart/files/images/thumb/".$productid.".jpg", "wb"); fwrite($handle, $thumb_imagedata_); fclose($handle); # reference thumbnail image to store in db $image_data[thumb_image]="/home/user/xcart/files/images/thumb/".$productid.".jpg"; # clean up ImageDestroy($photoImage); ImageDestroy($logoImage); #db_query("INSERT INTO $sql_tbl[thumbnails] (productid, image_path, image_type) VALUES ('$productid', '".addslashes($image_data["image"])."', '$image_data[image_type]')"); db_query("insert into $sql_tbl[thumbnails] (productid, image_path, thumb_path, image_type) values ('$productid', '".addslashes($image_data[image])."', '".addslashes($image_data[thumb_image])."', '$image_data[image_type]')"); # end of mod # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- } else { db_query("INSERT INTO $sql_tbl[thumbnails] (productid, image, image_type) VALUES ('$productid', '$image_data[image]', '$image_data[image_type]')"); } } $status = "created"; } else { # # Update the existing product # # Update the default price db_query("UPDATE $sql_tbl[pricing] SET price='$price' WHERE productid='$productid' AND quantity='1' AND membership='' AND $sql_tbl[pricing].variantid = 0"); if($fields['price'] == 'Y' && $productids) db_query("UPDATE $sql_tbl[pricing] SET price='$price' WHERE quantity='1' AND $sql_tbl[pricing].variantid = 0 AND membership=''".$products_condition); # If image was posted if ($image_posted) { # Get image content $image_data = func_get_image_content($file_upload_data, $productid); # Replace image (DB) or full path to image (FS) in the database if ($store_in == "FS") { # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # Update thumbnail with GD by B00MER (www.cart-lab.com) # get image $photoImage = ImageCreateFromJPEG($image_data["image"]); ImageAlphaBlending($photoImage, true); #ImageAntiAlias($photoImage, true); # get size of original image $size = getimagesize($image_data["image"]); # resize our original image $new_w = 75; $new_h = 75; $old_x=imageSX($photoImage); $old_y=imageSY($photoImage); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } # create image resource and resize $thumb_img = imagecreatetruecolor($thumb_w,$thumb_h); #imagecopyresized($thumb_img, $photoImage, 0,0,0,0, imagesx($thumb_img), imagesy($thumb_img), imagesx($photoImage), imagesy($photoImage)); imagecopyresampled($thumb_img, $photoImage, 0,0,0,0, imagesx($thumb_img), imagesy($thumb_img), imagesx($photoImage), imagesy($photoImage)); # begin output of new thumbnail ob_start(); ImageJPEG($thumb_img,"",90); $thumb_imagedata_ = ob_get_contents(); ob_end_clean(); # write thumbnail to a file $handle = fopen("/home/user/xcart/files/images/thumb/".$productid.".jpg", "wb"); fwrite($handle, $thumb_imagedata_); fclose($handle); # reference thumbnail image to store in db # this must be a full writeable and readable directory the webserver can write to safely $image_data[thumb_image]="/home/user/xcart/files/images/thumb/".$productid.".jpg"; # clean up ImageDestroy($photoImage); ImageDestroy($logoImage); $image_data["image"] = addslashes($image_data["image"]); #db_query("REPLACE INTO $sql_tbl[thumbnails] (productid, ".($store_in == "FS"?"image_path":"image").", image_type) VALUES ('$productid', '$image_data[image]', '$image_data[image_type]')"); db_query("REPLACE into $sql_tbl[thumbnails] (productid, ".($store_in == "FS"?"image_path":"image").", thumb_path, image_type) values ('$productid', '$image_data[image]', '$image_data[thumb_image]', '$image_data[image_type]')"); # end of mod # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Also there are two lines I kept in. imagecopyresampled ... and imagecopyresized. If your having issues you can try and swap the two out to see if you get different results. There is also another GD function call ImageAntiAlias, it may need to be uncommented/enabled as well.

References:

http://us2.php.net/imageantialias
http://us2.php.net/manual/en/function.imagecopyresampled.php
http://us2.php.net/manual/en/function.imagecopyresized.php
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #27  
Old 10-17-2005, 10:43 AM
  B00MER's Avatar 
B00MER B00MER is offline
 

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

Default Simple update script

Here's a simple script that may help with the updating of existing products:
Code:
<?php # grab all images paths and redefine and copy to new field # cart-lab.com require "./auth.php"; $sql=func_query("SELECT productid,image_path,image_type FROM $sql_tbl[thumbnails] WHERE image_type = 'image/pjpeg'"); foreach($sql as $k=>$v) { $small_thumb = eregi_replace("thumb","small",$v[image_path]); if(file_exists($small_thumb)) { db_query("UPDATE $sql_tbl[thumbnails] SET thumb_path='$small_thumb' WHERE productid='$v[productid]'"); print "Updating $v[productid]... "; } else { db_query("UPDATE $sql_tbl[thumbnails] SET thumb_path='' WHERE productid='$v[productid]'"); print "File Not Found. "; } } print "Done."; ?>
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #28  
Old 10-20-2005, 03:59 PM
 
creative xpress creative xpress is offline
 

Advanced Member
  
Join Date: Aug 2005
Posts: 71
 

Default

Boomer - Would I just put that script into its own php file and then run it or does this script go into an existing php page?
__________________
Xcart
Version: 4.1.6
Reply With Quote
  #29  
Old 10-21-2005, 10:08 AM
  B00MER's Avatar 
B00MER B00MER is offline
 

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

Default

No it would be a seperate php page. The script is useful if you have generated thumbnails via photoshop batch persay and are wanting to update the existing products with the new generated thumbnails.
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #30  
Old 10-21-2005, 01:18 PM
 
mffowler mffowler is offline
 

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

Default

Thanks again Boomer- I am going to give your code a whirl on one of our latest sites.....

I'll see what I can contribute once it's working the images.

- Mike
__________________
4.1.9
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 04:51 PM.

   

 
X-Cart forums © 2001-2020