22
33namespace SimpleSoftwareIO \QrCode ;
44
5+ use InvalidArgumentException ;
6+
57class ImageMerge
68{
79 /**
@@ -46,6 +48,13 @@ class ImageMerge
4648 */
4749 protected $ mergeImageWidth ;
4850
51+ /**
52+ * Holds the radio of the merging image.
53+ *
54+ * @var float
55+ */
56+ protected $ mergeRatio ;
57+
4958 /**
5059 * The height of the merge image after it is merged.
5160 *
@@ -131,11 +140,13 @@ protected function createImage()
131140 * Sets the objects properties.
132141 *
133142 * @param $percentage float The percentage that the merge image should take up.
143+ *
144+ * @return void
134145 */
135146 protected function setProperties ($ percentage )
136147 {
137148 if ($ percentage > 1 ) {
138- throw new \ InvalidArgumentException ('$percentage must be less than 1 ' );
149+ throw new InvalidArgumentException ('$percentage must be less than 1 ' );
139150 }
140151
141152 $ this ->sourceImageHeight = $ this ->sourceImage ->getHeight ();
@@ -150,21 +161,26 @@ protected function setProperties($percentage)
150161
151162 /**
152163 * Calculates the center of the source Image using the Merge image.
164+ *
165+ * @return void
153166 */
154- private function calculateCenter ()
167+ protected function calculateCenter ()
155168 {
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 ) );
158171 }
159172
160173 /**
161174 * Calculates the width of the merge image being placed on the source image.
162175 *
163176 * @param float $percentage
177+ *
178+ * @return void
164179 */
165- private function calculateOverlap ($ percentage )
180+ protected function calculateOverlap ($ percentage )
166181 {
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 );
169185 }
170186}
0 commit comments