Jump to:

3373 Posts in 998 Topics by 712 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: 822 Views
  • nekranox
    Avatar
    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:

    ContractsPage.php:

    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) {

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

    }

    Includes\Contracts.ss:

    <% if URLSegment != contracts %>

    <div id="contractsTitleBox">
       <% control ContractPage_ResizedImage %>
       $Logo.ResizedImage.URL
    <% end_control %>
       
    <h2>$Title</h2>
    ...

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Operations on Image Objects Link to this post

    Hi,

    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 %>

    Barry

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: Operations on Image Objects Link to this post

    Hi,

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

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

    hth

    Rich

    822 Views
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.