5

The images created for the configurable swatches are stretched to fit the square div and image proportions are ignored. Images that are rectangle shaped will end up being distorted.

This is what the image should look like (taken from the thumbs view in magento 1.8.1.0):

enter image description here

This is what it looks like for the actual swatch:

enter image description here

[Moderator edit: adding relevant comment to body]

There is a template located at catalog\product\view\type\options\configurable\swatches.phtml and the code responsible for the swatch images is as follows:

 <img src="<?php echo $_swatchUrl; ?>" alt="<?php echo $_option->label; ?>" width="<?php echo $_swatchInnerWidth ?>" height="<?php echo $_swatchInnerHeight ?>" />

Changing this will have no effect on the image proportions however.

6
  • PHP: when generating the pictures, ensure the correct width AND height are set. Moreover, add a style="width: ... ; height: ..." so the web browser processes the pictures faster. Commented Jan 14, 2015 at 15:23
  • I tried it via css but the generated images are already distorted so I need to change the php function itself. The magic should happen within app\code\core\Mage\ConfigurableSwatches\Helper\Swatchdimensios.php but I am afraid altering this file exceeds my skills...
    – loeffel
    Commented Jan 16, 2015 at 12:38
  • You should configure a template file (.phtml) like so templatemonster.com/help/… Commented Jan 19, 2015 at 8:37
  • 1
    There is a template located at catalog\product\view\type\options\configurable\swatches.phtml and the code responsible for the swatch images is as follows: <img src="<?php echo $_swatchUrl; ?>" alt="<?php echo $_option->label; ?>" width="<?php echo $_swatchInnerWidth ?>" height="<?php echo $_swatchInnerHeight ?>" /> Changing this will have no effect on the image proportions however.
    – loeffel
    Commented Jan 19, 2015 at 9:18
  • Please post the generated HTML.
    – benmarks
    Commented Feb 14, 2015 at 14:16

2 Answers 2

3

We ran into this and perhaps someone has a better solution, but we extended the configurable swatches productimage.php helper with our own module. Perhaps Magento intended everyone to create manual swatches for every product. That tis time consuming and we have products that does not work well for. They uses the Varien Image model which allowed them access to caching, but does not have the convenient default settings of the MAGE catalog/image model. The nice part is those functions are available.

If you don't know how to create a module would suggest making square images. "Do Not Edit The Core Files" Extend Them!

We extended the

protected function _resizeSwatchImage($filename, $tag, $width, $height)
{

below

$processor = new Varien_Image($sourceFilePath);

we added

$processor->backgroundColor(array(255, 255, 255)); 
// Set background color to white
$processor->constrainOnly(TRUE); 
//Constrain to proportions
$processor->keepAspectRatio(TRUE); 
//keep existing aspect ratio
$processor->keepFrame(TRUE);
//Kinda what it says
1
  • Exactly what I needed, thank you so much!
    – loeffel
    Commented Jun 5, 2015 at 8:34
0

Swatches are designed to have a standard width and height among all Swatches in Magento, unfortunately.

Without overriding the way Magento works, your best bet would be to either make your swatch images the same aspect ratio that Magento expects (by default a square) or to change the default swatch dimensions (if you have a set ratio you plan to use throughout your store).

The swatch width and height are set in the Configurable Swatches section of the Catalog configuration. Specifically, you'll find three sections: Swatch Dimensions on Product Detail Page, Swatch Dimensions in Product Listing, and Swatch Dimensions in Layered Navigation.

Magento automatically resizes the images to fit these dimensions before rendering them onto the page.

4
  • Shouldn't this be reported as a bug then? I use square images throughout my entire catalog and the dimensions are always correct. I don't understand why swatches should be calculated differently. Replacing thousand product images with square versions simply isn't an option.
    – loeffel
    Commented Feb 17, 2015 at 9:44
  • @loeffel I don't think they're intended to be used the way you're using them. I think their preliminary use case is for colours, sizes, etc. You seem to be including a full product picture for the swatch. Ideally you'd show something much more abstract and easier for the shopper to identify the difference.
    – Navarr
    Commented Feb 17, 2015 at 14:11
  • Navarr, I understand your point. But the fact, that magento will include my product images as swatches if I name them accordinly, is kind of contradictory to what you are saying. I have however accepted your reply, as I doubt we will find a true solution regarding this behavior. Thanks for your help!
    – loeffel
    Commented Feb 18, 2015 at 12:21
  • @loeffel That's true and unfortunate. It might be possible to write a patch for it, but I doubt Magento cares too much about the 1.x line when easy workarounds are available.
    – Navarr
    Commented Feb 18, 2015 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.