| 1: | <?php | 
| 2: |  | 
| 3: |  | 
| 4: |  | 
| 5: |  | 
| 6: |  | 
| 7: |  | 
| 8: |  | 
| 9: |  | 
| 10: |  | 
| 11: |  | 
| 12: |  | 
| 13: |  | 
| 14: |  | 
| 15: |  | 
| 16: |  | 
| 17: |  | 
| 18: |  | 
| 19: |  | 
| 20: |  | 
| 21: |  | 
| 22: |  | 
| 23: |  | 
| 24: | namespace WideImage\Operation; | 
| 25: |  | 
| 26: | use WideImage\Coordinate; | 
| 27: | use WideImage\Exception\GDFunctionResultException; | 
| 28: |  | 
| 29: |  | 
| 30: |  | 
| 31: |  | 
| 32: |  | 
| 33: |  | 
| 34: | class Merge | 
| 35: | { | 
| 36: |  | 
| 37: |  | 
| 38: |  | 
| 39: |  | 
| 40: |  | 
| 41: |  | 
| 42: |  | 
| 43: |  | 
| 44: |  | 
| 45: |  | 
| 46: | public function execute($base, $overlay, $left, $top, $pct) | 
| 47: | { | 
| 48: | $x = Coordinate::fix($left, $base->getWidth(), $overlay->getWidth()); | 
| 49: | $y = Coordinate::fix($top, $base->getHeight(), $overlay->getHeight()); | 
| 50: |  | 
| 51: | $result = $base->asTrueColor(); | 
| 52: | $result->alphaBlending(true); | 
| 53: | $result->saveAlpha(true); | 
| 54: |  | 
| 55: | if ($pct <= 0) { | 
| 56: | return $result; | 
| 57: | } | 
| 58: |  | 
| 59: | if ($pct < 100) { | 
| 60: | if (!imagecopymerge( | 
| 61: | $result->getHandle(), | 
| 62: | $overlay->getHandle(), | 
| 63: | $x, $y, 0, 0, | 
| 64: | $overlay->getWidth(), | 
| 65: | $overlay->getHeight(), | 
| 66: | $pct)) { | 
| 67: | throw new GDFunctionResultException("imagecopymerge() returned false"); | 
| 68: | } | 
| 69: | } else { | 
| 70: | if (!imagecopy( | 
| 71: | $result->getHandle(), | 
| 72: | $overlay->getHandle(), | 
| 73: | $x, $y, 0, 0, | 
| 74: | $overlay->getWidth(), | 
| 75: | $overlay->getHeight())) { | 
| 76: | throw new GDFunctionResultException("imagecopy() returned false"); | 
| 77: | } | 
| 78: | } | 
| 79: |  | 
| 80: | return $result; | 
| 81: | } | 
| 82: | } | 
| 83: |  |