wpfunnels
/
vendor
/
intervention
/
image
/
src
/
Intervention
/
Image
/
Gd
/
Commands
/
FillCommand.php
FillCommand.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at vendor/intervention/image/src/Intervention/Image/Gd/Commands/FillCommand.php
| 1 | <?php |
| 2 | |
| 3 | namespace Intervention\Image\Gd\Commands; |
| 4 | |
| 5 | use Intervention\Image\Commands\AbstractCommand; |
| 6 | use Intervention\Image\Gd\Color; |
| 7 | use Intervention\Image\Gd\Decoder; |
| 8 | |
| 9 | class FillCommand extends AbstractCommand |
| 10 | { |
| 11 | /** |
| 12 | * Fills image with color or pattern |
| 13 | * |
| 14 | * @param \Intervention\Image\Image $image |
| 15 | * @return boolean |
| 16 | */ |
| 17 | public function execute($image) |
| 18 | { |
| 19 | $filling = $this->argument(0)->value(); |
| 20 | $x = $this->argument(1)->type('digit')->value(); |
| 21 | $y = $this->argument(2)->type('digit')->value(); |
| 22 | |
| 23 | $width = $image->getWidth(); |
| 24 | $height = $image->getHeight(); |
| 25 | $resource = $image->getCore(); |
| 26 | |
| 27 | try { |
| 28 | |
| 29 | // set image tile filling |
| 30 | $source = new Decoder; |
| 31 | $tile = $source->init($filling); |
| 32 | imagesettile($image->getCore(), $tile->getCore()); |
| 33 | $filling = IMG_COLOR_TILED; |
| 34 | |
| 35 | } catch (\Intervention\Image\Exception\NotReadableException $e) { |
| 36 | |
| 37 | // set solid color filling |
| 38 | $color = new Color($filling); |
| 39 | $filling = $color->getInt(); |
| 40 | } |
| 41 | |
| 42 | imagealphablending($resource, true); |
| 43 | |
| 44 | if (is_int($x) && is_int($y)) { |
| 45 | |
| 46 | // resource should be visible through transparency |
| 47 | $base = $image->getDriver()->newImage($width, $height)->getCore(); |
| 48 | imagecopy($base, $resource, 0, 0, 0, 0, $width, $height); |
| 49 | |
| 50 | // floodfill if exact position is defined |
| 51 | imagefill($resource, $x, $y, $filling); |
| 52 | |
| 53 | // copy filled original over base |
| 54 | imagecopy($base, $resource, 0, 0, 0, 0, $width, $height); |
| 55 | |
| 56 | // set base as new resource-core |
| 57 | $image->setCore($base); |
| 58 | imagedestroy($resource); |
| 59 | |
| 60 | } else { |
| 61 | // fill whole image otherwise |
| 62 | imagefilledrectangle($resource, 0, 0, $width - 1, $height - 1, $filling); |
| 63 | } |
| 64 | |
| 65 | isset($tile) ? imagedestroy($tile->getCore()) : null; |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | } |
| 70 |