Code Duplication    Length = 41-41 lines in 2 locations

Imagine/Filter/Loader/BackgroundFilterLoader.php 1 location

@@ 38-78 (lines=41) @@
35
            list($width, $height) = $options['size'];
36
37
            $position = isset($options['position']) ? $options['position'] : 'center';
38
            switch ($position) {
39
                case 'topleft':
40
                    $x = 0;
41
                    $y = 0;
42
                    break;
43
                case 'top':
44
                    $x = ($width - $image->getSize()->getWidth()) / 2;
45
                    $y = 0;
46
                    break;
47
                case 'topright':
48
                    $x = $width - $image->getSize()->getWidth();
49
                    $y = 0;
50
                    break;
51
                case 'left':
52
                    $x = 0;
53
                    $y = ($height - $image->getSize()->getHeight()) / 2;
54
                    break;
55
                case 'center':
56
                    $x = ($width - $image->getSize()->getWidth()) / 2;
57
                    $y = ($height - $image->getSize()->getHeight()) / 2;
58
                    break;
59
                case 'right':
60
                    $x = $width - $image->getSize()->getWidth();
61
                    $y = ($height - $image->getSize()->getHeight()) / 2;
62
                    break;
63
                case 'bottomleft':
64
                    $x = 0;
65
                    $y = $height - $image->getSize()->getHeight();
66
                    break;
67
                case 'bottom':
68
                    $x = ($width - $image->getSize()->getWidth()) / 2;
69
                    $y = $height - $image->getSize()->getHeight();
70
                    break;
71
                case 'bottomright':
72
                    $x = $width - $image->getSize()->getWidth();
73
                    $y = $height - $image->getSize()->getHeight();
74
                    break;
75
                default:
76
                    throw new \InvalidArgumentException("Unexpected position '{$position}'");
77
                    break;
78
            }
79
80
            $size = new Box($width, $height);
81
            $topLeft = new Point($x, $y);

Imagine/Filter/Loader/WatermarkFilterLoader.php 1 location

@@ 59-99 (lines=41) @@
56
            $watermarkSize = $watermark->getSize();
57
        }
58
59
        switch ($options['position']) {
60
            case 'topleft':
61
                $x = 0;
62
                $y = 0;
63
                break;
64
            case 'top':
65
                $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
66
                $y = 0;
67
                break;
68
            case 'topright':
69
                $x = $size->getWidth() - $watermarkSize->getWidth();
70
                $y = 0;
71
                break;
72
            case 'left':
73
                $x = 0;
74
                $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
75
                break;
76
            case 'center':
77
                $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
78
                $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
79
                break;
80
            case 'right':
81
                $x = $size->getWidth() - $watermarkSize->getWidth();
82
                $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
83
                break;
84
            case 'bottomleft':
85
                $x = 0;
86
                $y = $size->getHeight() - $watermarkSize->getHeight();
87
                break;
88
            case 'bottom':
89
                $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
90
                $y = $size->getHeight() - $watermarkSize->getHeight();
91
                break;
92
            case 'bottomright':
93
                $x = $size->getWidth() - $watermarkSize->getWidth();
94
                $y = $size->getHeight() - $watermarkSize->getHeight();
95
                break;
96
            default:
97
                throw new \InvalidArgumentException("Unexpected position '{$options['position']}'");
98
                break;
99
        }
100
101
        return $image->paste($watermark, new Point($x, $y));
102
    }