2
2
3
3
namespace SimpleSoftwareIO \QrCode ;
4
4
5
+ use InvalidArgumentException ;
6
+
5
7
class ImageMerge
6
8
{
7
9
/**
@@ -46,6 +48,13 @@ class ImageMerge
46
48
*/
47
49
protected $ mergeImageWidth ;
48
50
51
+ /**
52
+ * Holds the radio of the merging image.
53
+ *
54
+ * @var float
55
+ */
56
+ protected $ mergeRatio ;
57
+
49
58
/**
50
59
* The height of the merge image after it is merged.
51
60
*
@@ -131,11 +140,13 @@ protected function createImage()
131
140
* Sets the objects properties.
132
141
*
133
142
* @param $percentage float The percentage that the merge image should take up.
143
+ *
144
+ * @return void
134
145
*/
135
146
protected function setProperties ($ percentage )
136
147
{
137
148
if ($ percentage > 1 ) {
138
- throw new \ InvalidArgumentException ('$percentage must be less than 1 ' );
149
+ throw new InvalidArgumentException ('$percentage must be less than 1 ' );
139
150
}
140
151
141
152
$ this ->sourceImageHeight = $ this ->sourceImage ->getHeight ();
@@ -150,21 +161,26 @@ protected function setProperties($percentage)
150
161
151
162
/**
152
163
* Calculates the center of the source Image using the Merge image.
164
+ *
165
+ * @return void
153
166
*/
154
- private function calculateCenter ()
167
+ protected function calculateCenter ()
155
168
{
156
- $ this ->centerY = ( $ this ->sourceImageHeight / 2 ) - ($ this ->postMergeImageHeight / 2 );
157
- $ this ->centerX = ( $ this ->sourceImageWidth / 2 ) - ($ this ->postMergeImageHeight / 2 );
169
+ $ this ->centerX = intval (( $ this ->sourceImageWidth / 2 ) - ($ this ->postMergeImageWidth / 2 ) );
170
+ $ this ->centerY = intval (( $ this ->sourceImageHeight / 2 ) - ($ this ->postMergeImageHeight / 2 ) );
158
171
}
159
172
160
173
/**
161
174
* Calculates the width of the merge image being placed on the source image.
162
175
*
163
176
* @param float $percentage
177
+ *
178
+ * @return void
164
179
*/
165
- private function calculateOverlap ($ percentage )
180
+ protected function calculateOverlap ($ percentage )
166
181
{
167
- $ this ->postMergeImageHeight = $ this ->sourceImageHeight * $ percentage ;
168
- $ this ->postMergeImageWidth = $ this ->sourceImageWidth * $ percentage ;
182
+ $ this ->mergeRatio = round ($ this ->mergeImageWidth / $ this ->mergeImageHeight , 2 );
183
+ $ this ->postMergeImageWidth = intval ($ this ->sourceImageWidth * $ percentage );
184
+ $ this ->postMergeImageHeight = intval ($ this ->postMergeImageWidth / $ this ->mergeRatio );
169
185
}
170
186
}
0 commit comments