@@ -197,98 +197,96 @@ public static function createCollage(array $config, array $srcImagePaths, string
197197 $ c ->textOnCollageLinespace = isset ($ collageJson ['text_linespace ' ]) ? $ collageJson ['text_linespace ' ] : $ c ->textOnCollageLinespace ;
198198 }
199199
200- if ($ c ->collageAllowSelection ) {
201- // JSON layout can only disable or customize text if admin has enabled it
202- if ($ adminTextOnCollageEnabled === 'enabled ' ) {
203- if (isset ($ collageJson ['text_disabled ' ]) && $ collageJson ['text_disabled ' ] === true ) {
204- $ c ->textOnCollageEnabled = 'disabled ' ;
205- } elseif (isset ($ collageJson ['text_alignment ' ]) && is_array ($ collageJson ['text_alignment ' ])) {
206- $ ta = $ collageJson ['text_alignment ' ];
207- $ c ->textOnCollageEnabled = 'enabled ' ;
208-
209- $ replace = ['x ' => self ::$ collageWidth , 'y ' => self ::$ collageHeight ];
210-
211- // Check if zone mode
212- if (isset ($ ta ['mode ' ]) && $ ta ['mode ' ] === 'zone ' ) {
213- // Zone mode: store zone parameters for Image::applyTextInZone()
214- $ c ->textZoneMode = true ;
215- $ c ->textZoneX = (float ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['x ' ] ?? '0 ' ));
216- $ c ->textZoneY = (float ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['y ' ] ?? '0 ' ));
217- $ c ->textZoneW = isset ($ ta ['w ' ]) ? (float ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['w ' ])) : 0 ;
218- $ c ->textZoneH = isset ($ ta ['h ' ]) ? (float ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['h ' ])) : 0 ;
219- $ c ->textZonePadding = isset ($ ta ['padding ' ]) ? (float ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['padding ' ])) : 0 ;
220- $ c ->textZoneAlign = $ ta ['align ' ] ?? 'center ' ;
221- $ c ->textZoneValign = $ ta ['valign ' ] ?? 'middle ' ;
222- $ c ->textZoneRotation = isset ($ ta ['rotation ' ]) ? (int ) $ ta ['rotation ' ] : 0 ;
223-
224- // In zone mode: ignore admin X/Y/Rotation values
225- // Keep admin font, color, text lines, fontSize (as start), lineHeight (as factor)
226- } else {
227- // Legacy mode: calculate X/Y position based on alignment
228- $ zoneX = Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['x ' ] ?? '0 ' ));
229- $ zoneY = Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['y ' ] ?? '0 ' ));
230- $ zoneW = isset ($ ta ['w ' ]) ? Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['w ' ])) : 0 ;
231- $ zoneH = isset ($ ta ['h ' ]) ? Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['h ' ])) : 0 ;
232-
233- if (isset ($ ta ['fontSize ' ])) {
234- $ c ->textOnCollageFontSize = (int ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['fontSize ' ]));
235- }
200+ // JSON layout can only disable or customize text if admin has enabled it
201+ if ($ adminTextOnCollageEnabled === 'enabled ' ) {
202+ if ($ c ->collageAllowSelection && isset ($ collageJson ['text_disabled ' ]) && $ collageJson ['text_disabled ' ] === true ) {
203+ $ c ->textOnCollageEnabled = 'disabled ' ;
204+ } elseif (isset ($ collageJson ['text_alignment ' ]) && is_array ($ collageJson ['text_alignment ' ])) {
205+ $ ta = $ collageJson ['text_alignment ' ];
206+ $ c ->textOnCollageEnabled = 'enabled ' ;
207+
208+ $ replace = ['x ' => self ::$ collageWidth , 'y ' => self ::$ collageHeight ];
209+
210+ // Check if zone mode
211+ if (isset ($ ta ['mode ' ]) && $ ta ['mode ' ] === 'zone ' ) {
212+ // Zone mode: store zone parameters for Image::applyTextInZone()
213+ $ c ->textZoneMode = true ;
214+ $ c ->textZoneX = (float ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['x ' ] ?? '0 ' ));
215+ $ c ->textZoneY = (float ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['y ' ] ?? '0 ' ));
216+ $ c ->textZoneW = isset ($ ta ['w ' ]) ? (float ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['w ' ])) : 0 ;
217+ $ c ->textZoneH = isset ($ ta ['h ' ]) ? (float ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['h ' ])) : 0 ;
218+ $ c ->textZonePadding = isset ($ ta ['padding ' ]) ? (float ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['padding ' ])) : 0 ;
219+ $ c ->textZoneAlign = $ ta ['align ' ] ?? 'center ' ;
220+ $ c ->textZoneValign = $ ta ['valign ' ] ?? 'middle ' ;
221+ $ c ->textZoneRotation = isset ($ ta ['rotation ' ]) ? (int ) $ ta ['rotation ' ] : 0 ;
222+
223+ // In zone mode: ignore admin X/Y/Rotation values
224+ // Keep admin font, color, text lines, fontSize (as start), lineHeight (as factor)
225+ } else {
226+ // Legacy mode: calculate X/Y position based on alignment
227+ $ zoneX = Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['x ' ] ?? '0 ' ));
228+ $ zoneY = Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['y ' ] ?? '0 ' ));
229+ $ zoneW = isset ($ ta ['w ' ]) ? Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['w ' ])) : 0 ;
230+ $ zoneH = isset ($ ta ['h ' ]) ? Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['h ' ])) : 0 ;
231+
232+ if (isset ($ ta ['fontSize ' ])) {
233+ $ c ->textOnCollageFontSize = (int ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['fontSize ' ]));
234+ }
236235
237- if (isset ($ ta ['rotation ' ])) {
238- $ c ->textOnCollageRotation = (int ) $ ta ['rotation ' ];
239- }
236+ if (isset ($ ta ['rotation ' ])) {
237+ $ c ->textOnCollageRotation = (int ) $ ta ['rotation ' ];
238+ }
240239
241- if (isset ($ ta ['lineHeight ' ])) {
242- $ c ->textOnCollageLinespace = (int ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['lineHeight ' ]));
243- }
240+ if (isset ($ ta ['lineHeight ' ])) {
241+ $ c ->textOnCollageLinespace = (int ) Helper::doMath (str_replace (array_keys ($ replace ), array_values ($ replace ), $ ta ['lineHeight ' ]));
242+ }
244243
245- $ align = $ ta ['align ' ] ?? 'start ' ;
246- $ valign = $ ta ['valign ' ] ?? 'top ' ;
244+ $ align = $ ta ['align ' ] ?? 'start ' ;
245+ $ valign = $ ta ['valign ' ] ?? 'top ' ;
247246
248- if ($ align === 'center ' || $ valign === 'middle ' ) {
249- $ textLines = [];
250- if (!empty ($ c ->textOnCollageLine1 )) {
251- $ textLines [] = $ c ->textOnCollageLine1 ;
252- }
253- if (!empty ($ c ->textOnCollageLine2 )) {
254- $ textLines [] = $ c ->textOnCollageLine2 ;
255- }
256- if (!empty ($ c ->textOnCollageLine3 )) {
257- $ textLines [] = $ c ->textOnCollageLine3 ;
258- }
247+ if ($ align === 'center ' || $ valign === 'middle ' ) {
248+ $ textLines = [];
249+ if (!empty ($ c ->textOnCollageLine1 )) {
250+ $ textLines [] = $ c ->textOnCollageLine1 ;
251+ }
252+ if (!empty ($ c ->textOnCollageLine2 )) {
253+ $ textLines [] = $ c ->textOnCollageLine2 ;
254+ }
255+ if (!empty ($ c ->textOnCollageLine3 )) {
256+ $ textLines [] = $ c ->textOnCollageLine3 ;
257+ }
259258
260- if (count ($ textLines ) > 0 && file_exists ($ c ->textOnCollageFont )) {
261- $ maxWidth = 0 ;
262- foreach ($ textLines as $ line ) {
263- $ bbox = imagettfbbox ($ c ->textOnCollageFontSize , $ c ->textOnCollageRotation , $ c ->textOnCollageFont , $ line );
264- if ($ bbox ) {
265- $ width = abs ($ bbox [2 ] - $ bbox [0 ]);
266- if ($ width > $ maxWidth ) {
267- $ maxWidth = $ width ;
268- }
259+ if (count ($ textLines ) > 0 && file_exists ($ c ->textOnCollageFont )) {
260+ $ maxWidth = 0 ;
261+ foreach ($ textLines as $ line ) {
262+ $ bbox = imagettfbbox ($ c ->textOnCollageFontSize , $ c ->textOnCollageRotation , $ c ->textOnCollageFont , $ line );
263+ if ($ bbox ) {
264+ $ width = abs ($ bbox [2 ] - $ bbox [0 ]);
265+ if ($ width > $ maxWidth ) {
266+ $ maxWidth = $ width ;
269267 }
270268 }
271- $ totalHeight = $ c ->textOnCollageFontSize + (count ($ textLines ) - 1 ) * $ c ->textOnCollageLinespace ;
272-
273- if ($ align === 'center ' ) {
274- $ c ->textOnCollageLocationX = (int ) ($ zoneX + ($ zoneW - $ maxWidth ) / 2 );
275- } else {
276- $ c ->textOnCollageLocationX = (int ) $ zoneX ;
277- }
269+ }
270+ $ totalHeight = $ c ->textOnCollageFontSize + (count ($ textLines ) - 1 ) * $ c ->textOnCollageLinespace ;
278271
279- if ($ valign === 'middle ' ) {
280- $ c ->textOnCollageLocationY = (int ) ($ zoneY + ($ zoneH - $ totalHeight ) / 2 + $ c ->textOnCollageFontSize );
281- } else {
282- $ c ->textOnCollageLocationY = (int ) ($ zoneY + $ c ->textOnCollageFontSize );
283- }
272+ if ($ align === 'center ' ) {
273+ $ c ->textOnCollageLocationX = (int ) ($ zoneX + ($ zoneW - $ maxWidth ) / 2 );
284274 } else {
285275 $ c ->textOnCollageLocationX = (int ) $ zoneX ;
286- $ c ->textOnCollageLocationY = (int ) $ zoneY ;
276+ }
277+
278+ if ($ valign === 'middle ' ) {
279+ $ c ->textOnCollageLocationY = (int ) ($ zoneY + ($ zoneH - $ totalHeight ) / 2 + $ c ->textOnCollageFontSize );
280+ } else {
281+ $ c ->textOnCollageLocationY = (int ) ($ zoneY + $ c ->textOnCollageFontSize );
287282 }
288283 } else {
289284 $ c ->textOnCollageLocationX = (int ) $ zoneX ;
290285 $ c ->textOnCollageLocationY = (int ) $ zoneY ;
291286 }
287+ } else {
288+ $ c ->textOnCollageLocationX = (int ) $ zoneX ;
289+ $ c ->textOnCollageLocationY = (int ) $ zoneY ;
292290 }
293291 }
294292 }
0 commit comments