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

Automatic Thumbnail Resize

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 09-30-2003, 08:22 AM
 
eleven eleven is offline
 

Senior Member
  
Join Date: Nov 2002
Location: Charlotte, NC, USA
Posts: 118
 

Default Automatic Thumbnail Resize

A client of mine didn't understand how to resize his images before he added them to the cart, so I wrote a quick and dirty mod to automatically resize them when he uploads them.

WARNING:
- it only works for jpg's (although it can easily be changed)
- it only works for images stored in the file system
- it uses GD. Some servers may not have GD installed (most will)
- the width is hard coded, you need to change it to the width of your images. It is line number 39 below.
- it will not work for batch imports, only thumbnails added through the Modify Products section

In /cart/include/func.php replace the function func_get_image_content with this:

Code:
function func_get_image_content($file_upload_data, $id) { global $config; $file_aliases_count_max = 99; switch($file_upload_data["imtype"]) { case "C": $config_data["location"] = $config["Images"]["icons_location"]; break; case "W": $config_data["location"] = $config["Images"]["pcicons_location"]; break; case "T": $config_data["location"] = $config["Images"]["thumbnails_location"]; break; case "D": $config_data["location"] = $config["Images"]["det_images_location"]; break; default: return false; } $file_path = $file_upload_data["file_path"]; if ($fd = fopen($file_path, "rb")) { if ($config_data["location"] == "FS") { # # Resize image # if (($file_upload_data["imtype"] == "T") && ($file_upload_data["image_type"] == "image/pjpeg")) { $img_src = ImageCreateFromjpeg ($imgname); $true_width = imagesx($img_src); $true_height = imagesy($img_src); # change this next line to control the width of the thumbnail $width = 360; $height = ($width/$true_width)*$true_height; $img_des = imagecreatetruecolor($width,$height); imagecopyresized ($img_des, $img_src, 0, 0, 0, 0, $width, $height, $true_width, $true_height); imagejpeg($img_des,$file_path,80); } # end resize # # ...else image is path to file # $image = $file_path; } else { # # If image should be stored in the database, get image content from file # if ($file_upload_data["source"] == "U") $file_size = 1000000; else $file_size = filesize($file_path); $image = addslashes(fread($fd, $file_size)); } fclose($fd); if ($file_upload_data["source"] == "L" && !empty($file_upload_data["dir_upload"])) { if ($config_data["location"] == "FS") { # # For FS storing. If image has been uploaded, move it to specified directory # $file_name = ($file_upload_data["imtype"]=="W"?"w_$id":($file_upload_data["imtype"]=="C"?"c_$id":($file_upload_data["imtype"]=="T"?"t_$id":"d_$id"))); $file_type = (strstr($file_path,"gif")?"gif":(strstr($file_path,"png")?"png":"jpg")); # # Check the existing file # $counter = 1; $file_name_tmp = $file_name; while (file_exists($file_upload_data["dir_upload"]."/".$file_name_tmp.".".$file_type) && $counter<$file_aliases_count_max) { $file_name_tmp = $file_name."_".sprintf("%02d", $counter); $counter++; } $file_name = $file_name_tmp; $image = $file_upload_data["dir_upload"]."/".$file_name.".".$file_type; copy($file_path, $image); @chmod($image, 0666); } # # Delete temporary file # @unlink($file_path); } } return array("image"=>$image, "image_type"=>$file_upload_data["image_type"], "image_x"=>$width, "image_y"=>$height, "file_size"=>$file_upload_data["file_size"]); }

I'm sure someone with a little more time on their hands could develop this into a nice mod that works for all images, not just thumbnails and jpg's and gets its settings from the admin area.
__________________
|| E L E V E N ||
Reply With Quote
  #2  
Old 09-30-2003, 12:57 PM
  groovico's Avatar 
groovico groovico is offline
 

X-Man
  
Join Date: Apr 2003
Location: Firetanksoftware.com
Posts: 2,326
 

Default

Depends on your version of GD too, the latest doesnt support GIF's at all and some will only resize images in 256 cols instead of supporting true colour.

Nifty mod tho kudos on posting it, I'll have to try it later on, maybe x-cart could put a similar on in the main program with a config for switching auto resizing on or off
__________________
Groovico

Used by X-carters the world over:
Marketing Manager Pro Bundle For X-cart
Featured Product Manager for X-cart
Feed manager pro for X-cart

http://www.firetanksoftware.com

Celebrating 7 Years of providing quality X-cart Add ons and X-cart Mods for x-cart 3.X to X-cart 4.4.X
Reply With Quote
  #3  
Old 09-30-2003, 01:45 PM
  shan's Avatar 
shan shan is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Birmingham, UK
Posts: 6,163
 

Default

Yeh, nice post..

I think it would be a great addition if xcart were to add a utility that resizes the images as standard. Many users have no idea on how to use image editing packages and this would save a lot of bother for them. It could create 2 sizes, one for thumbs and one for detailed images.
__________________
Looking for a reliable X-cart host ?
You wont go wrong with either of these.

EWD Hosting
Hands On Hosting
Reply With Quote
  #4  
Old 08-10-2009, 04:35 AM
 
ladybird ladybird is offline
 

Advanced Member
  
Join Date: Sep 2008
Posts: 93
 

Default Re: Automatic Thumbnail Resize

Quote:
Originally Posted by shan
Yeh, nice post..

I think it would be a great addition if xcart were to add a utility that resizes the images as standard. Many users have no idea on how to use image editing packages and this would save a lot of bother for them. It could create 2 sizes, one for thumbs and one for detailed images.

Hi Shan,

nice one! Do you think this would work for sub-category icon thumbnails? I have read the forum and upgraded the sub-cat tpl to now show icons at the sub cat level, but unfortunately it resizes the 3 menu columns based on the width of the images - would the above mod limit the thumbnail size for sub-cat? Or do you happen to know how to do this ...

See http://www.makeuwell.com.au/home.php?cat=66 for details of what is now happening (live site)

Cheers

L
__________________
x-cart gold 4.1.9
x-cart gold 4.1.5
www.makeuwell.com.au
www.amberbebe.com
Sydney Australia
Reply With Quote
  #5  
Old 11-29-2010, 08:10 PM
 
inteliboy1 inteliboy1 is offline
 

Member
  
Join Date: Jun 2010
Posts: 27
 

Default Re: Automatic Thumbnail Resize

Any updates on this? (quite an old post)

Re-sizing / cropping thumbnails would be a huge help for clients!
__________________
X-Cart Pro
4.4
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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 11:12 AM.

   

 
X-Cart forums © 2001-2020