function pad(\Imagine\Gd\Imagine $img, \Imagine\Image\Box $size, $fcolor = '#000', $ftransparency = 100) { $tsize = $img->getSize(); $x = $y = 0; if ($size->getWidth() > $tsize->getWidth()) { $x = round(($size->getWidth() - $tsize->getWidth()) / 2); } elseif ($size->getHeight() > $tsize->getHeight()) { $y = round(($size->getHeight() - $tsize->getHeight()) / 2); } $pasteto = new \Imagine\Image\Point($x, $y); $imagine = new \Imagine\Gd\Imagine(); $color = new \Imagine\Image\Color($fcolor, $ftransparency); $image = $imagine->create($size, $color); $image->paste($img, $pasteto); return $image; }