| @@ 64-81 (lines=18) @@ | ||
| 61 | * @param resource $imageResource |
|
| 62 | * @return self |
|
| 63 | */ |
|
| 64 | protected function calculateX($imageResource) |
|
| 65 | { |
|
| 66 | if (intval($this->_x) === $this->_x) return $this->_x; |
|
| 67 | ||
| 68 | $x = strtolower($this->_x); |
|
| 69 | ||
| 70 | $imageWidth = imagesx($imageResource); |
|
| 71 | $watermarkWidth = imagesx($this->GetWatermark()->GetImageResource()); |
|
| 72 | ||
| 73 | if ($x == 'left') { |
|
| 74 | $x = 0; |
|
| 75 | } elseif ($x == 'center') { |
|
| 76 | $x = $imageWidth / 2 - ($watermarkWidth / 2); |
|
| 77 | } elseif ($x == 'right') { |
|
| 78 | $x = $imageWidth - $watermarkWidth; |
|
| 79 | } |
|
| 80 | return intval($x); |
|
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * Use build-in logic to position the y of watermark |
|
| @@ 89-106 (lines=18) @@ | ||
| 86 | * @param resource $imageResource |
|
| 87 | * @return self |
|
| 88 | */ |
|
| 89 | public function calculateY($imageResource) |
|
| 90 | { |
|
| 91 | if (intval($this->_y) === $this->_y) return $this->_y; |
|
| 92 | ||
| 93 | $y = strtolower($this->_y); |
|
| 94 | ||
| 95 | $imageHeight = imagesy($imageResource); |
|
| 96 | $watermarkHeight = imagesy($this->GetWatermark()->GetImageResource()); |
|
| 97 | ||
| 98 | if ($y == 'top') { |
|
| 99 | $y = 0; |
|
| 100 | } elseif ($y == 'center') { |
|
| 101 | $y = $imageHeight / 2 - ($watermarkHeight / 2); |
|
| 102 | } elseif ($y == 'bottom') { |
|
| 103 | $y = $imageHeight - $watermarkHeight; |
|
| 104 | } |
|
| 105 | return intval($y); |
|
| 106 | } |
|
| 107 | ||
| 108 | /** |
|
| 109 | * Sets the image that will be used as watermark |
|