Skip to content

Instantly share code, notes, and snippets.

@mockiemockiz
Created September 13, 2015 15:39
Show Gist options
  • Save mockiemockiz/a5cd378cb037bd87b7ab to your computer and use it in GitHub Desktop.
Save mockiemockiz/a5cd378cb037bd87b7ab to your computer and use it in GitHub Desktop.
<?php
/**
* Created by PhpStorm.
* User: mockie
* Date: 13/09/15
* Time: 22:13
*/
namespace ImageManipulator\Utilities;
class ImageFrameCreator {
protected $expandingValues = [];
protected $path;
protected $baseImageManipulator;
protected $baseImage;
protected $imageAttr;
protected $newImage;
public function __construct(BaseImageManipulator $baseImageManipulator)
{
$this->baseImageManipulator = $baseImageManipulator;
$this->imageAttr = $this->baseImageManipulator->getImageAttributes();
$this->newImage = $this->baseImageManipulator->imageCreateFromAny();
}
protected function createBaseImage()
{
$expandingHeight = $this->expandingValues['top'] + $this->expandingValues['bottom'];
$expandingWidth = $this->expandingValues['left'] + $this->expandingValues['right'];
if (!$this->baseImage) {
$this->baseImage = imagecreatetruecolor(
$this->imageAttr['width'] + $expandingWidth,
$this->imageAttr['height'] + $expandingHeight
);
}
}
public function createFrame()
{
$center = ($this->expandingValues['left'] + $this->expandingValues['right']) / 2;
imagecopyresampled(
$this->baseImage,
$this->newImage,
$center,
0,
0,
0,
$this->imageAttr['width'],
$this->imageAttr['height'],
$this->imageAttr['width'],
$this->imageAttr['height']
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment