@@ -86,49 +86,34 @@ public function resizeWatermark($file)
8686 {
8787 JLoader::register ('JInterventionimage ' , JPATH_LIBRARIES . DIRECTORY_SEPARATOR . 'jinterventionimage ' . DIRECTORY_SEPARATOR . 'jinterventionimage.php ' );
8888 $ manager = JInterventionimage::getInstance (['driver ' => $ this ->getNameDriver ()]);
89- $ fileString = imagecreatefromstring (file_get_contents ($ file ));
90- $ image = $ manager ->make ($ fileString );
91- $ logo = imagecreatefromstring (file_get_contents ($ fileWatermark ));
92- $ logoWidth = imagesx ($ logo );
93- $ logoHeight = imagesy ($ logo );
94- $ imageWidth = imagesx ($ fileString );
95- $ imageHeight = imagesy ($ fileString );
89+ $ image = $ manager ->make ($ file );
90+
91+ $ managerForWatermark = JInterventionimage::getInstance (['driver ' => $ this ->getNameDriver ()]);
92+ $ watermark = $ managerForWatermark ->make ($ fileWatermark );
93+
94+ $ logoWidth = $ watermark ->width ();
95+ $ logoHeight = $ watermark ->height ();
96+ $ imageWidth = $ image ->width ();
97+ $ imageHeight = $ image ->height ();
9698
9799 if ((int )$ this ->paramsComponent ->get ('overlaypercent ' , 0 ))
98100 {
99101 //сжимаем водяной знак по процентному соотношению от изображения на который накладывается
100102 $ precent = (double )$ this ->paramsComponent ->get ('overlaypercentvalue ' , 10 );
101103 $ logoWidthMax = $ imageWidth / 100 * $ precent ;
102104 $ logoHeightMax = $ imageHeight / 100 * $ precent ;
103-
104- $ ratio = $ logoHeight / $ logoWidth ;
105- $ tmpWidth = $ logoWidthMax ;
106- $ tmpHeight = $ tmpWidth * $ ratio ;
107-
108- if ($ tmpHeight > $ logoHeightMax )
109- {
110- $ tmpHeight = $ logoHeightMax ;
111- $ tmpWidth = $ tmpHeight / $ ratio ;
112- }
113-
114- $ logoNew = imagecreatetruecolor ($ tmpWidth , $ tmpHeight );
115- imagesavealpha ($ logoNew , true );
116- imagefill ($ logoNew ,0 ,0 ,0x7fff0000 );
117- imagecopyresampled ($ logoNew , $ logo , 0 , 0 , 0 , 0 , $ tmpWidth , $ tmpHeight , $ logoWidth , $ logoHeight );
118- $ logo = $ logoNew ;
119- $ logoWidth = $ tmpWidth ;
120- $ logoHeight = $ tmpHeight ;
121- unset($ logoNew );
105+ $ watermark ->resize ((int )$ logoWidthMax , (int )$ logoHeightMax , function ($ constraint ) {
106+ $ constraint ->aspectRatio ();
107+ $ constraint ->upsize ();
108+ });
122109 }
123110
124111 if ($ logoWidth > $ imageWidth && $ logoHeight > $ imageHeight )
125112 {
126113 return false ;
127114 }
128115
129- $ watermark = $ manager ->make ($ logo );
130116 $ image ->insert ($ watermark , $ position , $ padding , $ padding );
131-
132117 $ image ->save ($ file );
133118
134119 }
@@ -168,7 +153,10 @@ public function resizeFit($file)
168153
169154 $ manager = JInterventionimage::getInstance (['driver ' => $ this ->getNameDriver ()]);
170155 $ manager ->make ($ file )
171- ->fit ($ newWidth , $ newHeight )
156+ ->resize ($ newWidth , $ newHeight , function ($ constraint ) {
157+ $ constraint ->aspectRatio ();
158+ $ constraint ->upsize ();
159+ })
172160 ->save ($ file );
173161 }
174162
0 commit comments