WP Ecommerce Scale Image instead of Cropping

Ok i recently had the problem where i wanted to define a max size for the images in my shopping cart. I didn’t want to set a static size for my entire carts images.

Eg I wanted it to be max of 300px height or width but not 300px wide and 300px high.

So if the image is landscape it would be 300px wide and whatever it works it out to be height (eg 200px, anything lower than 300px). If it was portrait then i want the largest dimension to be the height (at 300px with the above example).

Here are the things i did to achieve this.

Please note – you will need knowledge of PHP to achieve this.

First you need to add this section of code to the file misc.functions.php – located in WP Ecommerce folder/wpsc-includes/
Add this code to the switch($scaling_method) { statement (make sure it’s above the last option
case 'scale':
if (empty($width) || empty($height))
{
if (!empty($width))
$maxSize = $width;
else if (!empty($height))
$maxSize = $height;
else
{
//error
}
}else
{
if ($width > $height)
$maxSize = $width;
else
$maxSize = $height;
}

list($temp_w, $temp_h) = calculate_image_width_and_height($source_w, $source_h, $maxSize, $allowEnlarge=true);
$width = $temp_w;
$height = $temp_h;

break;

Replace

// select our scaling method
$scaling_method = 'cropping';

with

// select our scaling method
$scaling_method = 'scale';

You’ll also have to change theme.functions.php in the same directory as misc.functions.php
You’ll need to remove the css that the file creates.
Namely the Single View Styling
And the last 3 Default View Styling css statements.

The final change is part of your theme – i’m using the default theme, i’m not sure if you’ll have to change it for other themes or not.

Default theme – change single_product.php put a table around the following divs (below the div class=’textcol’ div)
<table width='100%' class='nocolour'>
<tr>
<td valign='top'>
<div>
Image Stuff is here
</div>
</td>
<td valign='top'>
<div>
...
</div>
</td>
</tr>
</table>

I think some css changes need to be done to get this to work (namely removing the postition:relative and some of the floats and positioning for imagecol and producttext)

Once that is all done – you need to go the Presentation area of the Settings Area of WP E-commerce. Go to the Single Product Image Size part and fill in only one of the text boxes, leave the other blank.
That should make it work for your images. I’ll be doing this for another client soon so if the process is different i’ll let you know

You can leave a response, or trackback from your own site.

Leave a Reply