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, Ed, biapar, Willr, Ingo, swaiba

$gd->writeTo function

Go to End



Community Member, 545 Posts

6 October 2010 at 6:45am

Edited: 06/10/2010 8:47am

I'm looking for more information on writeTo() function. I want to be able to change the names of resampled images for SEO purposes and I'm wondering how to properly set the the writeTo function on an extended image class:

function generateSmallimage($gd) {
   return $gd;

The class documentation doesn't provide much direction on the actual use of the function.


After a little more playing around with code pulled from the IMage Object I've gotten this far

function generateSmallimage($gd) {
	   //Get asset Folder
	   $folder = $this->ParentID ? $this->Parent()->Filename : ASSETS_DIR . "/";
	   //Get Current Filename
	   $filename = $this->Name;
	   //Get Extension
	   $ext = strtolower(substr($filename, strrpos($filename,'.')+1));
	   //set new path and filename;
	   $newFilename = $folder . "_resampled/my-file-name." . $ext;
	  $smallImage = $gd->resizeRatio(150,150);
	  $smallImage = $smallImage->writeTo($newFilename);
      return $smallImage;

This will generate a resized image in the correct folder, but it still returns a link to a filename titled smallImage-originalFilename