public function setBackgroundImage($image, $mode = null)
{
$this->preModify();
$image = ltrim($image, "/");
$image = PIMCORE_DOCUMENT_ROOT . "/" . $image;
if (is_file($image)) {
$backgroundImage = imagecreatefromstring(file_get_contents($image));
list($backgroundImageWidth, $backgroundImageHeight) = getimagesize($image);
if ($mode == "cropTopLeft") {
$newImg = $this->createImage($this->getWidth(), $this->getHeight());
imagecopyresampled($newImg, $backgroundImage, 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $this->getWidth(), $this->getHeight());
imagealphablending($newImg, true);
imagecopyresampled($newImg, $this->resource, 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $this->getWidth(), $this->getHeight());
$this->resource = $newImg;
} else {
// default behavior (fit)
$newImg = $this->createImage($this->getWidth(), $this->getHeight());
imagecopyresampled($newImg, $backgroundImage, 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $backgroundImageWidth, $backgroundImageHeight);
imagealphablending($newImg, true);
imagecopyresampled($newImg, $this->resource, 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $this->getWidth(), $this->getHeight());
$this->resource = $newImg;
}
}
$this->postModify();
return $this;
}