3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 715 Views |
-
Conditional Image Sizes

20 July 2010 at 12:00am Last edited: 20 July 2010 12:23am
Where can I find info on controlling image sizes.?
I have a pull down in my cms "CSSBoxStyle" and based on that pull down value i want to set the size of the image displayed.
if they choose nostyle then its 218 pixels wide
else its 294 pixels widei'm struggling with my if statements
Is it best to do this in the SS file or the PHP image class?
example PHP
<?php
class RightContent extends DataObject {
static $db = array(
'Title' => 'Text',
'Description' => 'HTMLText',
'ImageLink' => 'Varchar(255)',
'CSSBoxStyle' => "Enum('styleone, styletwo, stylethree, stylefour, nostyle')"
);
static $singular_name = 'RightContent';
static $plural_name = 'RightContents';
static $has_one = array(
'Page' => 'Page',
'SideScreenImage' => 'RightContent_SideScreenImage'
);
static $defaults = array(
'Title' => ''
);
public function getCMSFields_forPopup() {
$fields = new FieldSet(
new ImageField('SideScreenImage','MainImage (Optional)'),
new TextField('ImageLink', 'Add URL Link to Image (Optional)'),
new TextField('Title', 'Title'),
new SimpleHTMLEditorField('Description','HTML'),
new DropdownField('CSSBoxStyle', 'CSSBoxStyle', singleton('RightContent')->dbObject('CSSBoxStyle')->enumValues())//'getCMSFields_forPopup'
);
return $fields;
} //getCMSFields_forPopup
} //dataobject
class RightContent_SideScreenImage extends Image {
function generateWebsiteThumnail($gd) {
$gd->setQuality(80);
//if nostyle is chosen i want it to be 218
return $gd->ResizeByWidth(218);
//return $gd->ResizeByWidth(194);
}
}
?>
SS file
<% control RightContents %><% control SideScreenImage %>
$SetWidth(218)
<% end_control %><% end_control %>
-
Re: Conditional Image Sizes

20 July 2010 at 12:20am
I managed to do it in the ss file.
<% if CSSBoxStyle == "nostyle" %>
<% control SideScreenImage %>
$SetWidth(218)
<% end_control %><% else %>
<% control SideScreenImage %>
$SetWidth(194)
<% end_control %>
<% end_if %>I couldn't seem to do it in the php as it was suggesting CSSBoxStyle was an unknown variable
whats the difference between doing in in the ss file or the php file?
is it related to performance?
| 715 Views | ||
|
Page:
1
|
Go to Top |

