Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » Flip an 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: 988 Views
  • dompie
    Avatar
    Community Member
    88 Posts

    Flip an Image Link to this post

    Hello,

    I try to add a new function to the Image class which will flip an image horizontally, vertically or both. It should work exactly the same way like SetRatioSize only with an additional parameter.

    I added the following Code to the Image class as a first tryout:

       public function SetFlipImage($width, $height, $type) {
          return $this->getFormattedImage('SetFlipImage', $width, $height);
       }
       
       public function generateSetFlipImage(GD $gd, $width, $height, $type){
          return $gd->resizeRatio($width, $height);
       }

    But when calling from Template with $Image.SetFlipImage(248,123,hor) Silverstripe stops with:

    [Warning] Missing argument 1 for Image::SetFlipImage(), called in /public_html/silverstripe_base/sapphire/core/ViewableData.php on line 369 and defined

    That I do not understand, because removing the last argument leads to

    [Warning] Missing argument 3 for Image::SetFlipImage()

    which is absolutely correct. Why does Silverstripe not recoginize my third parameter?

  • ampedup
    Avatar
    Community Member
    133 Posts

    Re: Flip an Image Link to this post

    public function SetFlipImage($width, $height, $type) {
    return $this->getFormattedImage('SetFlipImage', $width, $height);
    }

    public function generateSetFlipImage(GD $gd, $width, $height, $type){
    return $gd->resizeRatio($width, $height);
    }

    Change the name of one of your functions. SetFlipImage and generateSetFlipImage are essentially the same function name, because the word generate gets dropped off.
    That is, calling $Image.SetFlipImage() will call either of these functions, and it looks like it's calling the second function.

    The warning you are getting from Silverstripe is you are Missing 1 argument. It expects 4 arguments, because it is trying to call the generateSetFlipImage function.

  • dompie
    Avatar
    Community Member
    88 Posts

    Re: Flip an Image Link to this post

    Well, I figured out how to use the functions...however, I stumbled upon the following lines in several function of the GD class.

          $output = clone $this;
          $output->setGD($newGD);
          return $output;

    Is there a special reason for that? I'd like to return right away just $this with $this->gd holding my flipped image.

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