@@ -490,6 +490,17 @@ private function createWatermarkBasedOnPosition(
490
490
$ watermark = $ this ->createWaterMark ($ watermark , $ this ->getWatermarkWidth (), $ this ->getWatermarkHeight ());
491
491
}
492
492
493
+ /**
494
+ * Fixes issue with transparent watermark and a non-truecolor image.
495
+ * blending mode is allowed for truecolor images only.
496
+ * @see imagealphablending()
497
+ */
498
+ if (!imageistruecolor ($ this ->_imageHandler )) {
499
+ $ newImage = $ this ->createTruecolorImageCopy ();
500
+ $ this ->imageDestroy ();
501
+ $ this ->_imageHandler = $ newImage ;
502
+ }
503
+
493
504
if ($ this ->getWatermarkPosition () == self ::POSITION_TILE ) {
494
505
$ tile = true ;
495
506
} elseif ($ this ->getWatermarkPosition () == self ::POSITION_STRETCH ) {
@@ -871,6 +882,9 @@ private function imagecopymergeWithAlphaFix(
871
882
$ pct
872
883
) {
873
884
if ($ pct >= 100 ) {
885
+ if (false === imagealphablending ($ dst_im , true )) {
886
+ return false ;
887
+ }
874
888
return imagecopy ($ dst_im , $ src_im , $ dst_x , $ dst_y , $ src_x , $ src_y , $ src_w , $ src_h );
875
889
}
876
890
@@ -919,4 +933,24 @@ private function imagecopymergeWithAlphaFix(
919
933
920
934
return $ result ;
921
935
}
936
+
937
+ /**
938
+ * Create truecolor image copy of current image
939
+ *
940
+ * @return resource
941
+ */
942
+ private function createTruecolorImageCopy ()
943
+ {
944
+ $ this ->_getTransparency ($ this ->_imageHandler , $ this ->_fileType , $ isAlpha );
945
+
946
+ $ newImage = imagecreatetruecolor ($ this ->_imageSrcWidth , $ this ->_imageSrcHeight );
947
+
948
+ if ($ isAlpha ) {
949
+ $ this ->_saveAlpha ($ newImage );
950
+ }
951
+
952
+ imagecopy ($ newImage , $ this ->_imageHandler , 0 , 0 , 0 , 0 , $ this ->_imageSrcWidth , $ this ->_imageSrcHeight );
953
+
954
+ return $ newImage ;
955
+ }
922
956
}
0 commit comments