Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Operations on Image Objects

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 878 Views
  • nekranox
    Community Member
    31 Posts

    Operations on Image Objects Link to this post

    Hey guys,

    I want to perform paddedResize on an image object, I think I've sub-classed the image class correctly but the edited image isn't coming through into the template. Would really appreciate it if someone could have a quick look at this for me:


    class ContractPage extends Page {

       static $singular_name = 'Contract';
       static $allowed_children = 'none';
       static $can_be_root = false;   
       public static $db = array(
          "start" => "Varchar(50)",
          "end" => "Varchar(50)",
          "Type" => "Varchar(20)",

        static $has_one = array(
        'Logo' => 'ContractPage_ResizedImage'

       function getCMSFields() {
          $typeOptions = array(
           'Project Management' => 'Project Management',
           'Business Support' => 'Business Support',
          $fields = parent::getCMSFields();
           $fields->addFieldToTab('Root.Content.Main', new DropdownField('Type', 'Type', $typeOptions));   
          $fields->addFieldToTab('Root.Content.Main', new DateField('start', 'Start Date'));
          $fields->addFieldToTab('Root.Content.Main', new DateField('end', 'End Date'));      
          $fields->addFieldToTab('Root.Content.Main', new ImageField("Logo"));      
          return $fields;

    class ContractPage_Controller extends Page_Controller {


    class ContractPage_ResizedImage extends Image {

    function generateResizedImage($gd) {

    return $gd->paddedResize(100,83);



    <% if URLSegment != contracts %>

    <div id="contractsTitleBox">
       <% control ContractPage_ResizedImage %>
    <% end_control %>

  • swaiba
    Forum Moderator
    1792 Posts

    Re: Operations on Image Objects Link to this post


    this might help... resizing the image on the template without the extra code in the controller...

    <% control DataObjectSetOfImages %>
       <% control ImageDataObject %>
          <% control PaddedImage(100,83) %>
          <% end_control %>
       <% end_control %>
    <% end_control %>


  • TotalNet
    Community Member
    181 Posts

    Re: Operations on Image Objects Link to this post


    I don't think you need the control (control ContractPage_ResizedImage)

    You should be able to call $Logo.ResizedImage.URL



Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.