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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

Flip an Image


Go to End


3 Posts   1455 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, 135 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.