How to apply an image style based on a condition? I've been following this discussion: How to apply an image style based on a condition (a date for ex.)? but unfortunately it has not been a success.

I would like to have the image to change based on a boolean field type being checked or not. When I check the On Sale checkbox, I would like the product image to be displayed with a different image-style.

My boolean field is named field_commerce_saleprice_on_sale. 
1st image style is product_grid. 
2nd image style on_sale.
In node--product.tpl.php I found the line
          

Thanks in advance for your help.
If you want to do it in template file, you can access your boolean variable using $node object. You can do following way :

if ($node-&gt;field_boolean[LANGUAGE_NONE][0]['value']) {
  print theme('image_style', array('path' =&gt; $node-&gt;field_image['und'][0]['uri'], 'style_name' =&gt; 'style1_name'));
}
else {
  print theme('image_style', array('path' =&gt; $node-&gt;field_image['und'][0]['uri'], 'style_name' =&gt; 'style2_name'));
}


Or :

If you are using panels, then you can use visibility rule to the fields by adding it twice with different image style.