@@ -337,6 +337,97 @@ public function rotateDataProvider()
337
337
);
338
338
}
339
339
340
+ /**
341
+ * Test if alpha transparency is correctly handled
342
+ *
343
+ * @param string $image
344
+ * @param string $watermark
345
+ * @param int $alphaPercentage
346
+ * @param array $comparePoint1
347
+ * @param array $comparePoint2
348
+ * @param string $adapterType
349
+ *
350
+ * @dataProvider imageWatermarkWithAlphaTransparencyDataProvider
351
+ * @depends testOpen
352
+ * @depends testImageSize
353
+ */
354
+ public function testWatermarkWithAlphaTransparency (
355
+ $ image ,
356
+ $ watermark ,
357
+ $ alphaPercentage ,
358
+ $ comparePoint1 ,
359
+ $ comparePoint2 ,
360
+ $ adapterType
361
+ ) {
362
+ $ imageAdapter = $ this ->_getAdapter ($ adapterType );
363
+ $ imageAdapter ->open ($ image );
364
+
365
+ $ watermarkAdapter = $ this ->_getAdapter ($ adapterType );
366
+ $ watermarkAdapter ->open ($ watermark );
367
+
368
+ list ($ comparePoint1X , $ comparePoint1Y ) = $ comparePoint1 ;
369
+ list ($ comparePoint2X , $ comparePoint2Y ) = $ comparePoint2 ;
370
+
371
+ $ imageAdapter
372
+ ->setWatermarkImageOpacity ($ alphaPercentage )
373
+ ->setWatermarkPosition (\Magento \Framework \Image \Adapter \AbstractAdapter::POSITION_TOP_LEFT )
374
+ ->watermark ($ watermark );
375
+
376
+ $ comparePoint1Color = $ imageAdapter ->getColorAt ($ comparePoint1X , $ comparePoint1Y );
377
+ unset($ comparePoint1Color ['alpha ' ]);
378
+
379
+ $ comparePoint2Color = $ imageAdapter ->getColorAt ($ comparePoint2X , $ comparePoint2Y );
380
+ unset($ comparePoint2Color ['alpha ' ]);
381
+
382
+ $ result = $ this ->_compareColors ($ comparePoint1Color , $ comparePoint2Color );
383
+ $ message = sprintf (
384
+ '%s should be different to %s due to alpha transparency ' ,
385
+ join (', ' , $ comparePoint1Color ),
386
+ join (', ' , $ comparePoint2Color )
387
+ );
388
+ $ this ->assertFalse ($ result , $ message );
389
+ }
390
+
391
+ public function imageWatermarkWithAlphaTransparencyDataProvider ()
392
+ {
393
+ return $ this ->_prepareData (
394
+ [
395
+ // Watermark with alpha channel, 25%
396
+ [
397
+ $ this ->_getFixture ('watermark_alpha_base_image.jpg ' ),
398
+ $ this ->_getFixture ('watermark_alpha.png ' ),
399
+ 25 ,
400
+ [ 23 , 3 ],
401
+ [ 23 , 30 ]
402
+ ],
403
+ // Watermark with alpha channel, 50%
404
+ [
405
+ $ this ->_getFixture ('watermark_alpha_base_image.jpg ' ),
406
+ $ this ->_getFixture ('watermark_alpha.png ' ),
407
+ 50 ,
408
+ [ 23 , 3 ],
409
+ [ 23 , 30 ]
410
+ ],
411
+ // Watermark with no alpha channel, 50%
412
+ [
413
+ $ this ->_getFixture ('watermark_alpha_base_image.jpg ' ),
414
+ $ this ->_getFixture ('watermark.png ' ),
415
+ 50 ,
416
+ [ 3 , 3 ],
417
+ [ 23 ,3 ]
418
+ ],
419
+ // Watermark with no alpha channel, 100%
420
+ [
421
+ $ this ->_getFixture ('watermark_alpha_base_image.jpg ' ),
422
+ $ this ->_getFixture ('watermark.png ' ),
423
+ 100 ,
424
+ [ 3 , 3 ],
425
+ [ 3 , 60 ]
426
+ ],
427
+ ]
428
+ );
429
+ }
430
+
340
431
/**
341
432
* Checks if watermark exists on the right position
342
433
*
@@ -350,10 +441,10 @@ public function rotateDataProvider()
350
441
* @param int $colorY
351
442
* @param string $adapterType
352
443
*
353
- * @dataProvider imageWatermarkDataProvider
444
+ * @dataProvider imageWatermarkPositionDataProvider
354
445
* @depends testOpen
355
446
*/
356
- public function testWatermark (
447
+ public function testWatermarkPosition (
357
448
$ image ,
358
449
$ watermark ,
359
450
$ width ,
@@ -387,7 +478,7 @@ public function testWatermark(
387
478
$ this ->assertFalse ($ result , $ message );
388
479
}
389
480
390
- public function imageWatermarkDataProvider ()
481
+ public function imageWatermarkPositionDataProvider ()
391
482
{
392
483
return $ this ->_prepareData (
393
484
[
0 commit comments