Commit 7e92f056c for imagemagick.org
commit 7e92f056c51240a214087b5d8c3a442b001fea78
Author: Chi-Wei Lee <levi74108520963@gmail.com>
Date: Sat Oct 3 21:14:41 2026 +0800
Avoid font metrics for montages without text (#8998)
Apply the patch supplied by brc-dd in issue #8667 and cover the Wand API
with an unavailable font file.
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
diff --git a/MagickCore/montage.c b/MagickCore/montage.c
index 03e459cdc..4a8cea627 100644
--- a/MagickCore/montage.c
+++ b/MagickCore/montage.c
@@ -533,7 +533,7 @@ MagickExport Image *MontageImageList(const ImageInfo *image_info,
draw_info->stroke=montage_info->stroke;
draw_info->fill=montage_info->fill;
draw_info->text=AcquireString("");
- (void) GetTypeMetrics(image_list[0],draw_info,&metrics,exception);
+ (void) memset(&metrics,0,sizeof(metrics));
texture=NewImageList();
if (montage_info->texture != (char *) NULL)
{
@@ -546,10 +546,6 @@ MagickExport Image *MontageImageList(const ImageInfo *image_info,
*/
title=InterpretImageProperties(clone_info,image_list[0],montage_info->title,
exception);
- title_offset=0;
- if (montage_info->title != (char *) NULL)
- title_offset=(size_t) (2*(metrics.ascent-metrics.descent)*
- MultilineCensus(title)+2*extract_info.y);
number_lines=0;
for (i=0; i < (ssize_t) number_images; i++)
{
@@ -559,6 +555,12 @@ MagickExport Image *MontageImageList(const ImageInfo *image_info,
if (MultilineCensus(value) > number_lines)
number_lines=MultilineCensus(value);
}
+ if ((montage_info->title != (char *) NULL) || (number_lines != 0))
+ (void) GetTypeMetrics(image_list[0],draw_info,&metrics,exception);
+ title_offset=0;
+ if (montage_info->title != (char *) NULL)
+ title_offset=(size_t) (2*(metrics.ascent-metrics.descent)*
+ MultilineCensus(title)+2*extract_info.y);
/*
Allocate next structure.
*/
diff --git a/tests/wandtest.c b/tests/wandtest.c
index 824403455..ad3f479c0 100644
--- a/tests/wandtest.c
+++ b/tests/wandtest.c
@@ -5501,6 +5501,57 @@ int main(int argc,char **argv)
}
profile=(unsigned char *) MagickRelinquishMemory(profile);
magick_wand=DestroyMagickWand(magick_wand);
+ {
+ DrawingWand
+ *montage_draw;
+
+ MagickWand
+ *montage_input,
+ *montage_wand;
+
+ PixelWand
+ *montage_pixel;
+
+ (void) FormatLocaleFile(stdout,"Montage without text...\n");
+ montage_input=NewMagickWand();
+ montage_draw=NewDrawingWand();
+ montage_pixel=NewPixelWand();
+ (void) PixelSetColor(montage_pixel,"rgb(255,0,0)");
+ status=MagickNewImage(montage_input,2,2,montage_pixel);
+ if (status == MagickFalse)
+ ThrowAPIException(montage_input);
+ (void) PixelSetColor(montage_pixel,"rgb(0,0,255)");
+ status=MagickNewImage(montage_input,2,2,montage_pixel);
+ if (status == MagickFalse)
+ ThrowAPIException(montage_input);
+ (void) DrawSetFont(montage_draw,"@montage-font-does-not-exist.ttf");
+ montage_wand=MagickMontageImage(montage_input,montage_draw,"2x1",
+ "2x2+0+0",UnframeMode,(const char *) NULL);
+ if ((montage_wand == (MagickWand *) NULL) ||
+ (MagickGetExceptionType(montage_input) != UndefinedException))
+ ThrowAPIException(montage_input);
+ if ((MagickGetImageWidth(montage_wand) != 4) ||
+ (MagickGetImageHeight(montage_wand) != 2))
+ {
+ (void) FormatLocaleFile(stderr,"Unexpected montage dimensions\n");
+ exit(1);
+ }
+ status=MagickGetImagePixelColor(montage_wand,0,0,montage_pixel);
+ if ((status == MagickFalse) ||
+ (PixelGetRedQuantum(montage_pixel) != (Quantum) QuantumRange) ||
+ (PixelGetGreenQuantum(montage_pixel) != 0) ||
+ (PixelGetBlueQuantum(montage_pixel) != 0))
+ ThrowAPIException(montage_wand);
+ status=MagickGetImagePixelColor(montage_wand,2,0,montage_pixel);
+ if ((status == MagickFalse) || (PixelGetRedQuantum(montage_pixel) != 0) ||
+ (PixelGetGreenQuantum(montage_pixel) != 0) ||
+ (PixelGetBlueQuantum(montage_pixel) != (Quantum) QuantumRange))
+ ThrowAPIException(montage_wand);
+ montage_wand=DestroyMagickWand(montage_wand);
+ montage_pixel=DestroyPixelWand(montage_pixel);
+ montage_draw=DestroyDrawingWand(montage_draw);
+ montage_input=DestroyMagickWand(montage_input);
+ }
(void) FormatLocaleFile(stdout,"Wand tests pass.\n");
MagickWandTerminus();
return(0);