Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

Flip an Image


Reply


3 Posts   1133 Views

Avatar
dompie

Community Member, 88 Posts

8 September 2010 at 2:47am

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?

Avatar
3dgoo

Community Member, 133 Posts

8 September 2010 at 6:20pm

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.

Avatar
dompie

Community Member, 88 Posts

8 September 2010 at 8:39pm

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.