Jump to:

23478 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » SetWidth works, resize doesn't?

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 2 3
Go to End
Author Topic: 4050 Views
  • ttyl
    Avatar
    Community Member
    114 Posts

    SetWidth works, resize doesn't? Link to this post

    new to ss and I find this very odd, hoping somebody can point me in the right direction.

    when I do this:

    $myImage.SetWidth(150)

    it outputs the image with the set width as expected - very cool.

    however, when I do this:

    $myImage.resize(150, 150)

    I get "(150, 150)" on the page. am I doing something wrong?

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: SetWidth works, resize doesn't? Link to this post

    Hi!

    Wrong syntax, use instead: $myImage.SetSize(150,150) (http://doc.silverstripe.org/doku.php?id=image)

    Hope it helps,
    Juan

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: SetWidth works, resize doesn't? Link to this post

    that causes everything to break...very confused.

    Source

    173    
    174    public function SetWidth($width) {
    175       return $this->getFormattedImage('SetWidth', $width);
    176    }
    177    
    178    public function SetHeight($height) {
    179       return $this->getFormattedImage('SetHeight', $height);
    180    }
    181    
    182    public function SetSize($width, $height) {
    183       return $this->getFormattedImage('SetSize', $width, $height);
    184    }
    185    
    186    /**
    187     * Resize this Image by width, keeping aspect ratio. Use in templates with $SetWidth.
    188     * @return GD

    Trace

    * Image->SetSize()
    * call_user_func_array(Array,Array)
    Line 408 of ViewableData.php
    * ViewableData->XML_val(SetSize,,1)
    Line 182 of .cache.Applications.MAMP.htdocs.ss.themes.tutorial.templates.Layout.FacultyPage.ss
    * include(/private/var/folders/C2/C2RzM9F2GDqG5p2gxYQxyE+++TM/-Tmp-/silverstripe-cache-Applications-MAMP-htdocs-ss/.cache.Applications.MAMP.htdocs.ss.themes.tutorial.templates.Layout.FacultyPage.ss)
    Line 354 of SSViewer.php
    * SSViewer->process(FacultyPage_Controller)
    Line 346 of SSViewer.php
    * SSViewer->process(FacultyPage_Controller)
    Line 175 of Controller.php
    * Controller->handleAction(HTTPRequest)
    Line 129 of RequestHandler.php
    * RequestHandler->handleRequest(HTTPRequest)
    Line 122 of Controller.php
    * Controller->handleRequest(HTTPRequest)
    Line 29 of ModelAsController.php
    * ModelAsController->handleRequest(HTTPRequest)
    Line 277 of Director.php
    * Director::handleRequest(HTTPRequest,Session)
    Line 121 of Director.php
    * Director::direct(/person/)
    Line 118 of main.php

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: SetWidth works, resize doesn't? Link to this post

    I’m confused too!!! I’m getting ‘Missing argument 1 for Image::SetSize()’.

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: SetWidth works, resize doesn't? Link to this post

    i havent had much luck with using 1 method to proportionately resize an image but you can check the orientation in the template, and depending on the orientation either call setHeight or setWidth.

    hope it helps

  • patjnr
    Avatar
    Community Member
    101 Posts

    Re: SetWidth works, resize doesn't? Link to this post

    With my experience working with images the best way is to make use of the php gd function by extend the image class.

    1. create a php file called FittedImage.php

    <?php
    class FittedImage extends Image {

    function generateMainImage($gd) {
    $gd->setQuality(80);
    return $gd->resizeRatio(370,240);
    }

    function generateThumbImage($gd) {
    $gd->setQuality(80);
    return $gd->resize(120,80);
    }

    }
    ?>

    2.

    static $has_one = array(
    'GalleryImage' => 'FittedImage ',

    );

    3.

    in you Template it can be

    <img src="$GalleryImage.ThumbImage.URL" />

    this will be for the small image which (may be ) on mouseover it displays the MainImage in another div

    for the Main image

    <img src="$GalleryImage.MainImage.URL" />

    let me know if you need a URL for the site where this functionality is in place.

    hope this makes sense

    this is clearly explained here

    http://doc.silverstripe.org/doku.php?id=recipes:imageupload

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: SetWidth works, resize doesn't? Link to this post

    Hi,

    I use the same method of Pat jnr...

    class Product extends Page {
    static $db = array(
    'DescrBreve' => 'Text',
    'Evidence' => 'Boolean'
    );

    static $has_one = array(
    'ProdottoImage1' => 'Product_Image',
    )

    etc...

    class Product_Image extends Image {
    function generateCroppedImage($gd) {
          $gd->setQuality(90);
          return $gd->croppedResize(300,130);
       }   

    }

    theni into template ( .ss file )

    $ProdottoImage1.CroppedImage

    Bye

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: SetWidth works, resize doesn't? Link to this post

    I understand I can extend my classes, which is why I like silverstipe thus far. but should I view the prebuilt image function as unreliable? as I'm still in my newbie phase are there other types of things I should just write my own functionality for? I'm not sure I want to be getting into any scenarios where example code from tutorials isn't something I can count on...

    4050 Views
Page: 1 2 3
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.