Created
September 13, 2015 15:39
-
-
Save mockiemockiz/a5cd378cb037bd87b7ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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