@@ -490,6 +490,17 @@ private function createWatermarkBasedOnPosition(
490490 $ watermark = $ this ->createWaterMark ($ watermark , $ this ->getWatermarkWidth (), $ this ->getWatermarkHeight ());
491491 }
492492
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+
493504 if ($ this ->getWatermarkPosition () == self ::POSITION_TILE ) {
494505 $ tile = true ;
495506 } elseif ($ this ->getWatermarkPosition () == self ::POSITION_STRETCH ) {
@@ -871,6 +882,9 @@ private function imagecopymergeWithAlphaFix(
871882 $ pct
872883 ) {
873884 if ($ pct >= 100 ) {
885+ if (false === imagealphablending ($ dst_im , true )) {
886+ return false ;
887+ }
874888 return imagecopy ($ dst_im , $ src_im , $ dst_x , $ dst_y , $ src_x , $ src_y , $ src_w , $ src_h );
875889 }
876890
@@ -919,4 +933,24 @@ private function imagecopymergeWithAlphaFix(
919933
920934 return $ result ;
921935 }
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+ }
922956}
0 commit comments