Jump to:

23471 Posts in 18937 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Solved :resizing image

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 2542 Views
  • Rishi
    Avatar
    Community Member
    97 Posts

    Solved :resizing image Link to this post

    i have created a page type where i am uploading an image and i am displaying it on the page but i need to resize the image not cropped because when i am croping it cropped the image in ratio which sometime result n a very bad image so i just want to resize the image not crop my code so far is

    php page
    <?php
    class ProfilePage extends Page {
    static $db = array(
    );
    static $has_one = array(
    'Photo' => 'Image'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Images", new ImageField('Photo'));
    return $fields;
    }

    static $defaults = array(
    'ShowInMenus' => false
    );

    }

    class ProfilePage_Controller extends Page_Controller {

    }
    ?>

    template page

    <% control Photo %>
    <% control CroppedImage(540,340) %>
    <img src ="$URL" alt="" />
    <% end_control %>
    <% end_control %>

    thank you in advance

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Solved :resizing image Link to this post

    Well if you don't want to crop the image then perhaps use something like PaddedImage() or SetSize which doesn't crop the image.

    You can see a list of what you can use on http://doc.silverstripe.org/doku.php?id=image#resizing_in_templates.

  • Rishi
    Avatar
    Community Member
    97 Posts

    Re: Solved :resizing image Link to this post

    thanks a lot Willr
    this is the document i was looking for .you have saved me thanks once again but i have encountered few problem on implementing the functions.

    1. when i am calling the picture as simple variable it is showing up
    code

    $Photo

    2.when I am calling it with SetWidth(80) it is working fine

    code
    $Photo.SetWidth(80)

    3.but when i am calling it using SetSize(80,80) it is giving me error as

    Missing argument 1 for Image::SetSize()
    the code i have tried are

    $Photo.SetSize(80 , 80)
    $Photo.SetSize(80, 80)
    $Photo.SetSize(80,80)

    nothing is working

    4.when i am calling it as PaddedImage(80, 80) i am getting this error

    imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions

    the code i have tried are
    $Photo.PaddedImage(80, 80)
    $Photo.PaddedImage(80,80)
    $Photo.PaddedImage(80 , 80)

    Thank you in advance

  • Rishi
    Avatar
    Community Member
    97 Posts

    Re: Solved :resizing image Link to this post

    Please help me out in this

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Solved :resizing image Link to this post

    Try <% control Photo %>$PaddedImage(80,80)<% end_control %> or even <% control Photo %><% control PaddedImage(80, 80) %>$URL<% end_control %><% end_control %> and see if either of those work (The template parser is a bit hit and miss like this).

  • Rishi
    Avatar
    Community Member
    97 Posts

    Re: Solved :resizing image Link to this post

    Thank you.. the below code works great for me

    <% control Photo %><% control PaddedImage(80, 80) %>$URL<% end_control %><% end_control %>
    thank a lot

    2542 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.