@@ -442,6 +442,7 @@ public function watermark($imagePath, $positionX = 0, $positionY = 0, $opacity =
442
442
$ this ->_getCallback ('create ' , $ watermarkFileType , 'Unsupported watermark image format. ' ),
443
443
$ imagePath
444
444
);
445
+ //$watermark = $this->prepareWatermark($watermark, $watermarkFileType);
445
446
446
447
$ merged = false ;
447
448
@@ -599,6 +600,49 @@ public function watermark($imagePath, $positionX = 0, $positionY = 0, $opacity =
599
600
$ this ->refreshImageDimensions ();
600
601
}
601
602
603
+ /**
604
+ * @param resource $watermark
605
+ * @param string $watermarkFileType
606
+ * @return resource
607
+ */
608
+ private function prepareWatermark ($ watermark , $ watermarkFileType )
609
+ {
610
+ if (imagesx ($ watermark ) > $ this ->_imageSrcWidth
611
+ || imagesy ($ watermark ) > $ this ->_imageSrcHeight ) {
612
+ $ widthRatio = imagesx ($ watermark )/$ this ->_imageSrcWidth ;
613
+ $ heightRatio = imagesy ($ watermark )/$ this ->_imageSrcHeight ;
614
+ $ newWidth = ($ widthRatio > $ heightRatio )
615
+ ? round (imagesx ($ watermark )/$ widthRatio ) : round (imagesx ($ watermark )/$ heightRatio );
616
+ $ newHeight = ($ widthRatio > $ heightRatio )
617
+ ? round (imagesy ($ watermark )/$ widthRatio ) : round (imagesy ($ watermark )/$ heightRatio );
618
+ $ isAlpha = false ;
619
+ $ isTrueColor = false ;
620
+ $ this ->_getTransparency ($ watermark , $ watermarkFileType , $ isAlpha , $ isTrueColor );
621
+ if ($ isTrueColor ) {
622
+ $ newImage = imagecreatetruecolor ($ newWidth , $ newHeight );
623
+ } else {
624
+ $ newImage = imagecreate ($ newWidth , $ newHeight );
625
+ }
626
+ if ($ isAlpha ) {
627
+ $ this ->_saveAlpha ($ newImage );
628
+ }
629
+ imagecopyresampled (
630
+ $ newImage ,
631
+ $ watermark ,
632
+ 0 ,
633
+ 0 ,
634
+ 0 ,
635
+ 0 ,
636
+ $ newWidth ,
637
+ $ newHeight ,
638
+ imagesx ($ watermark ),
639
+ imagesy ($ watermark )
640
+ );
641
+ $ watermark = $ newImage ;
642
+ }
643
+ return $ watermark ;
644
+ }
645
+
602
646
/**
603
647
* Crop image
604
648
*
@@ -859,6 +903,10 @@ private function imagecopymergeWithAlphaFix(
859
903
return false ;
860
904
}
861
905
906
+ if (false === imagesavealpha ($ tmpImg , true )) {
907
+ return false ;
908
+ }
909
+
862
910
if (false === imagecopy ($ tmpImg , $ src_im , 0 , 0 , 0 , 0 , $ sizeX , $ sizeY )) {
863
911
return false ;
864
912
}
@@ -868,6 +916,14 @@ private function imagecopymergeWithAlphaFix(
868
916
return false ;
869
917
}
870
918
919
+ if (false === imagealphablending ($ dst_im , true )) {
920
+ return false ;
921
+ }
922
+
923
+ if (false === imagesavealpha ($ dst_im , true )) {
924
+ return false ;
925
+ }
926
+
871
927
$ result = imagecopy ($ dst_im , $ tmpImg , $ dst_x , $ dst_y , $ src_x , $ src_y , $ src_w , $ src_h );
872
928
imagedestroy ($ tmpImg );
873
929
0 commit comments