2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % M M OOO N N TTTTT AAA GGGG EEEEE %
7 % MM MM O O NN N T A A G E %
8 % M M M O O N N N T AAAAA G GG EEE %
9 % M M O O N NN T A A G G E %
10 % M M OOO N N T A A GGG EEEEE %
13 % MagickCore Methods to Create Image Thumbnails %
20 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/annotate.h"
45 #include "MagickCore/client.h"
46 #include "MagickCore/color.h"
47 #include "MagickCore/composite.h"
48 #include "MagickCore/constitute.h"
49 #include "MagickCore/decorate.h"
50 #include "MagickCore/draw.h"
51 #include "MagickCore/effect.h"
52 #include "MagickCore/enhance.h"
53 #include "MagickCore/exception.h"
54 #include "MagickCore/exception-private.h"
55 #include "MagickCore/fx.h"
56 #include "MagickCore/gem.h"
57 #include "MagickCore/geometry.h"
58 #include "MagickCore/image.h"
59 #include "MagickCore/image-private.h"
60 #include "MagickCore/list.h"
61 #include "MagickCore/memory_.h"
62 #include "MagickCore/monitor.h"
63 #include "MagickCore/monitor-private.h"
64 #include "MagickCore/montage.h"
65 #include "MagickCore/option.h"
66 #include "MagickCore/pixel.h"
67 #include "MagickCore/quantize.h"
68 #include "MagickCore/property.h"
69 #include "MagickCore/resize.h"
70 #include "MagickCore/resource_.h"
71 #include "MagickCore/string_.h"
72 #include "MagickCore/utility.h"
73 #include "MagickCore/utility-private.h"
74 #include "MagickCore/version.h"
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 % C l o n e M o n t a g e I n f o %
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 % CloneMontageInfo() makes a copy of the given montage info structure. If
88 % NULL is specified, a new image info structure is created initialized to
91 % The format of the CloneMontageInfo method is:
93 % MontageInfo *CloneMontageInfo(const ImageInfo *image_info,
94 % const MontageInfo *montage_info)
96 % A description of each parameter follows:
98 % o image_info: the image info.
100 % o montage_info: the montage info.
103 MagickExport MontageInfo *CloneMontageInfo(const ImageInfo *image_info,
104 const MontageInfo *montage_info)
109 clone_info=(MontageInfo *) AcquireMagickMemory(sizeof(*clone_info));
110 if (clone_info == (MontageInfo *) NULL)
111 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
112 GetMontageInfo(image_info,clone_info);
113 if (montage_info == (MontageInfo *) NULL)
115 if (montage_info->geometry != (char *) NULL)
116 clone_info->geometry=AcquireString(montage_info->geometry);
117 if (montage_info->tile != (char *) NULL)
118 clone_info->tile=AcquireString(montage_info->tile);
119 if (montage_info->title != (char *) NULL)
120 clone_info->title=AcquireString(montage_info->title);
121 if (montage_info->frame != (char *) NULL)
122 clone_info->frame=AcquireString(montage_info->frame);
123 if (montage_info->texture != (char *) NULL)
124 clone_info->texture=AcquireString(montage_info->texture);
125 if (montage_info->font != (char *) NULL)
126 clone_info->font=AcquireString(montage_info->font);
127 clone_info->pointsize=montage_info->pointsize;
128 clone_info->border_width=montage_info->border_width;
129 clone_info->shadow=montage_info->shadow;
130 clone_info->fill=montage_info->fill;
131 clone_info->stroke=montage_info->stroke;
132 clone_info->background_color=montage_info->background_color;
133 clone_info->border_color=montage_info->border_color;
134 clone_info->matte_color=montage_info->matte_color;
135 clone_info->gravity=montage_info->gravity;
136 (void) CopyMagickString(clone_info->filename,montage_info->filename,
138 clone_info->debug=IsEventLogging();
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 % D e s t r o y M o n t a g e I n f o %
151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 % DestroyMontageInfo() deallocates memory associated with montage_info.
155 % The format of the DestroyMontageInfo method is:
157 % MontageInfo *DestroyMontageInfo(MontageInfo *montage_info)
159 % A description of each parameter follows:
161 % o montage_info: Specifies a pointer to an MontageInfo structure.
165 MagickExport MontageInfo *DestroyMontageInfo(MontageInfo *montage_info)
167 if (montage_info->debug != MagickFalse)
168 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
169 assert(montage_info != (MontageInfo *) NULL);
170 assert(montage_info->signature == MagickSignature);
171 if (montage_info->geometry != (char *) NULL)
172 montage_info->geometry=(char *)
173 RelinquishMagickMemory(montage_info->geometry);
174 if (montage_info->tile != (char *) NULL)
175 montage_info->tile=DestroyString(montage_info->tile);
176 if (montage_info->title != (char *) NULL)
177 montage_info->title=DestroyString(montage_info->title);
178 if (montage_info->frame != (char *) NULL)
179 montage_info->frame=DestroyString(montage_info->frame);
180 if (montage_info->texture != (char *) NULL)
181 montage_info->texture=(char *) RelinquishMagickMemory(
182 montage_info->texture);
183 if (montage_info->font != (char *) NULL)
184 montage_info->font=DestroyString(montage_info->font);
185 montage_info->signature=(~MagickSignature);
186 montage_info=(MontageInfo *) RelinquishMagickMemory(montage_info);
187 return(montage_info);
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 % G e t M o n t a g e I n f o %
199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 % GetMontageInfo() initializes montage_info to default values.
203 % The format of the GetMontageInfo method is:
205 % void GetMontageInfo(const ImageInfo *image_info,
206 % MontageInfo *montage_info)
208 % A description of each parameter follows:
210 % o image_info: a structure of type ImageInfo.
212 % o montage_info: Specifies a pointer to a MontageInfo structure.
215 MagickExport void GetMontageInfo(const ImageInfo *image_info,
216 MontageInfo *montage_info)
218 assert(image_info != (const ImageInfo *) NULL);
219 assert(image_info->signature == MagickSignature);
220 if (image_info->debug != MagickFalse)
221 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
222 image_info->filename);
223 assert(montage_info != (MontageInfo *) NULL);
224 (void) ResetMagickMemory(montage_info,0,sizeof(*montage_info));
225 (void) CopyMagickString(montage_info->filename,image_info->filename,
227 montage_info->geometry=AcquireString(DefaultTileGeometry);
228 if (image_info->font != (char *) NULL)
229 montage_info->font=AcquireString(image_info->font);
230 montage_info->gravity=CenterGravity;
231 montage_info->pointsize=image_info->pointsize;
232 montage_info->fill.alpha=OpaqueAlpha;
233 montage_info->stroke.alpha=(Quantum) TransparentAlpha;
234 montage_info->background_color=image_info->background_color;
235 montage_info->border_color=image_info->border_color;
236 montage_info->matte_color=image_info->matte_color;
237 montage_info->debug=IsEventLogging();
238 montage_info->signature=MagickSignature;
242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 % M o n t a g e I m a g e L i s t %
250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 % MontageImageList() is a layout manager that lets you tile one or more
253 % thumbnails across an image canvas.
255 % The format of the MontageImageList method is:
257 % Image *MontageImageList(const ImageInfo *image_info,
258 % const MontageInfo *montage_info,Image *images,
259 % ExceptionInfo *exception)
261 % A description of each parameter follows:
263 % o image_info: the image info.
265 % o montage_info: Specifies a pointer to a MontageInfo structure.
267 % o images: Specifies a pointer to an array of Image structures.
269 % o exception: return any errors or warnings in this structure.
273 static void GetMontageGeometry(char *geometry,const size_t number_images,
274 ssize_t *x_offset,ssize_t *y_offset,size_t *tiles_per_column,
275 size_t *tiles_per_row)
279 (void) GetGeometry(geometry,x_offset,y_offset,tiles_per_row,tiles_per_column);
280 if ((*tiles_per_column == 0) && (*tiles_per_row == 0))
281 *tiles_per_column=(size_t) sqrt((double) number_images);
282 if (*tiles_per_column == 0)
283 *tiles_per_column=(size_t)
284 ceil((double) number_images/(*tiles_per_row));
285 if (*tiles_per_row == 0)
286 *tiles_per_row=(size_t)
287 ceil((double) number_images/(*tiles_per_column));
290 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
297 static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
304 #if defined(__cplusplus) || defined(c_plusplus)
308 static int SceneCompare(const void *x,const void *y)
314 image_1=(Image **) x;
315 image_2=(Image **) y;
316 return((int) ((*image_1)->scene-(*image_2)->scene));
319 #if defined(__cplusplus) || defined(c_plusplus)
323 MagickExport Image *MontageImages(const Image *images,
324 const MontageInfo *montage_info,ExceptionInfo *exception)
332 image_info=AcquireImageInfo();
333 montage_image=MontageImageList(image_info,montage_info,images,exception);
334 image_info=DestroyImageInfo(image_info);
335 return(montage_image);
338 MagickExport Image *MontageImageList(const ImageInfo *image_info,
339 const MontageInfo *montage_info,const Image *images,ExceptionInfo *exception)
341 #define MontageImageTag "Montage/Image"
342 #define TileImageTag "Tile/Image"
345 tile_geometry[MaxTextExtent],
377 MagickProgressMonitor
421 assert(images != (Image *) NULL);
422 assert(images->signature == MagickSignature);
423 if (images->debug != MagickFalse)
424 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
425 assert(montage_info != (MontageInfo *) NULL);
426 assert(montage_info->signature == MagickSignature);
427 assert(exception != (ExceptionInfo *) NULL);
428 assert(exception->signature == MagickSignature);
429 number_images=GetImageListLength(images);
430 master_list=ImageListToArray(images,exception);
431 image_list=master_list;
433 if (master_list == (Image **) NULL)
434 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
435 thumbnail=NewImageList();
436 for (i=0; i < (ssize_t) number_images; i++)
438 image=CloneImage(image_list[i],0,0,MagickTrue,exception);
439 if (image == (Image *) NULL)
441 (void) ParseAbsoluteGeometry("0x0+0+0",&image->page);
442 progress_monitor=SetImageProgressMonitor(image,(MagickProgressMonitor) NULL,
444 flags=ParseRegionGeometry(image,montage_info->geometry,&geometry,exception);
445 thumbnail=ThumbnailImage(image,geometry.width,geometry.height,exception);
446 if (thumbnail == (Image *) NULL)
448 image_list[i]=thumbnail;
449 (void) SetImageProgressMonitor(image,progress_monitor,image->client_data);
450 proceed=SetImageProgress(image,TileImageTag,(MagickOffsetType) i,
452 if (proceed == MagickFalse)
454 image=DestroyImage(image);
456 if (i < (ssize_t) number_images)
458 if (thumbnail == (Image *) NULL)
460 for (tile=0; (ssize_t) tile <= i; tile++)
461 if (image_list[tile] != (Image *) NULL)
462 image_list[tile]=DestroyImage(image_list[tile]);
463 master_list=(Image **) RelinquishMagickMemory(master_list);
464 return((Image *) NULL);
467 Sort image list by increasing tile number.
469 for (i=0; i < (ssize_t) number_images; i++)
470 if (image_list[i]->scene == 0)
472 if (i == (ssize_t) number_images)
473 qsort((void *) image_list,(size_t) number_images,sizeof(*image_list),
476 Determine tiles per row and column.
478 tiles_per_column=(size_t) sqrt((double) number_images);
479 tiles_per_row=(size_t) ceil((double) number_images/tiles_per_column);
482 if (montage_info->tile != (char *) NULL)
483 GetMontageGeometry(montage_info->tile,number_images,&x_offset,&y_offset,
484 &tiles_per_column,&tiles_per_row);
486 Determine tile sizes.
488 concatenate=MagickFalse;
489 SetGeometry(image_list[0],&extract_info);
490 extract_info.x=(ssize_t) montage_info->border_width;
491 extract_info.y=(ssize_t) montage_info->border_width;
492 if (montage_info->geometry != (char *) NULL)
495 Initialize tile geometry.
497 flags=GetGeometry(montage_info->geometry,&extract_info.x,&extract_info.y,
498 &extract_info.width,&extract_info.height);
499 if ((extract_info.x == 0) && (extract_info.y == 0))
500 concatenate=((flags & RhoValue) == 0) && ((flags & SigmaValue) == 0) ?
501 MagickTrue : MagickFalse;
503 border_width=montage_info->border_width;
505 if (montage_info->frame != (char *) NULL)
508 absolute_geometry[MaxTextExtent];
510 (void) ResetMagickMemory(&frame_info,0,sizeof(frame_info));
511 frame_info.width=extract_info.width;
512 frame_info.height=extract_info.height;
513 (void) FormatLocaleString(absolute_geometry,MaxTextExtent,"%s!",
514 montage_info->frame);
515 flags=ParseMetaGeometry(absolute_geometry,&frame_info.outer_bevel,
516 &frame_info.inner_bevel,&frame_info.width,&frame_info.height);
517 if ((flags & HeightValue) == 0)
518 frame_info.height=frame_info.width;
519 if ((flags & XiValue) == 0)
520 frame_info.outer_bevel=(ssize_t) frame_info.width/2;
521 if ((flags & PsiValue) == 0)
522 frame_info.inner_bevel=frame_info.outer_bevel;
523 frame_info.x=(ssize_t) frame_info.width;
524 frame_info.y=(ssize_t) frame_info.height;
525 bevel_width=(size_t) MagickMax(frame_info.inner_bevel,
526 frame_info.outer_bevel);
527 border_width=(size_t) MagickMax((ssize_t) frame_info.width,
528 (ssize_t) frame_info.height);
530 for (i=0; i < (ssize_t) number_images; i++)
532 if (image_list[i]->columns > extract_info.width)
533 extract_info.width=image_list[i]->columns;
534 if (image_list[i]->rows > extract_info.height)
535 extract_info.height=image_list[i]->rows;
538 Initialize draw attributes.
540 clone_info=CloneImageInfo(image_info);
541 clone_info->background_color=montage_info->background_color;
542 clone_info->border_color=montage_info->border_color;
543 draw_info=CloneDrawInfo(clone_info,(DrawInfo *) NULL);
544 if (montage_info->font != (char *) NULL)
545 (void) CloneString(&draw_info->font,montage_info->font);
546 if (montage_info->pointsize != 0.0)
547 draw_info->pointsize=montage_info->pointsize;
548 draw_info->gravity=CenterGravity;
549 draw_info->stroke=montage_info->stroke;
550 draw_info->fill=montage_info->fill;
551 draw_info->text=AcquireString("");
552 (void) GetTypeMetrics(image_list[0],draw_info,&metrics,exception);
553 texture=NewImageList();
554 if (montage_info->texture != (char *) NULL)
556 (void) CopyMagickString(clone_info->filename,montage_info->texture,
558 texture=ReadImage(clone_info,exception);
561 Determine the number of lines in an next label.
563 title=InterpretImageProperties(clone_info,image_list[0],montage_info->title,
566 if (montage_info->title != (char *) NULL)
567 title_offset=(size_t) (2*(metrics.ascent-metrics.descent)*
568 MultilineCensus(title)+2*extract_info.y);
570 for (i=0; i < (ssize_t) number_images; i++)
572 value=GetImageProperty(image_list[i],"label",exception);
573 if (value == (const char *) NULL)
575 if (MultilineCensus(value) > number_lines)
576 number_lines=MultilineCensus(value);
579 Allocate next structure.
581 tile_image=AcquireImage((ImageInfo *) NULL,exception);
582 montage=AcquireImage(clone_info,exception);
583 montage->background_color=montage_info->background_color;
585 images_per_page=(number_images-1)/(tiles_per_row*tiles_per_column)+1;
587 total_tiles=(size_t) number_images;
588 for (i=0; i < (ssize_t) images_per_page; i++)
591 Determine bounding box.
593 tiles_per_page=tiles_per_row*tiles_per_column;
596 if (montage_info->tile != (char *) NULL)
597 GetMontageGeometry(montage_info->tile,number_images,&x_offset,&y_offset,
599 tiles_per_page=tiles_per_row*tiles_per_column;
600 y_offset+=(ssize_t) title_offset;
605 for (tile=0; tile < (ssize_t) tiles_per_page; tile++)
607 if (tile < (ssize_t) number_images)
609 width=concatenate != MagickFalse ? image_list[tile]->columns :
611 if (image_list[tile]->rows > max_height)
612 max_height=image_list[tile]->rows;
614 x_offset+=(ssize_t) (width+2*(extract_info.x+border_width));
615 if (x_offset > (ssize_t) bounds.width)
616 bounds.width=(size_t) x_offset;
617 if (((tile+1) == (ssize_t) tiles_per_page) ||
618 (((tile+1) % tiles_per_row) == 0))
621 if (montage_info->tile != (char *) NULL)
622 GetMontageGeometry(montage_info->tile,number_images,&x_offset,&y,
624 height=concatenate != MagickFalse ? max_height : extract_info.height;
625 y_offset+=(ssize_t) (height+(extract_info.y+(ssize_t) border_width)*2+
626 (metrics.ascent-metrics.descent+4)*number_lines+
627 (montage_info->shadow != MagickFalse ? 4 : 0));
628 if (y_offset > (ssize_t) bounds.height)
629 bounds.height=(size_t) y_offset;
633 if (montage_info->shadow != MagickFalse)
636 Initialize montage image.
638 (void) CopyMagickString(montage->filename,montage_info->filename,
640 montage->columns=MagickMax(bounds.width,1);
641 montage->rows=MagickMax(bounds.height,1);
642 (void) SetImageBackgroundColor(montage,exception);
644 Set montage geometry.
646 montage->montage=AcquireString((char *) NULL);
649 while (tile < MagickMin((ssize_t) tiles_per_page,(ssize_t) number_images))
651 extent+=strlen(image_list[tile]->filename)+1;
654 montage->directory=(char *) AcquireQuantumMemory(extent,
655 sizeof(*montage->directory));
656 if ((montage->montage == (char *) NULL) ||
657 (montage->directory == (char *) NULL))
658 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
661 if (montage_info->tile != (char *) NULL)
662 GetMontageGeometry(montage_info->tile,number_images,&x_offset,&y_offset,
664 y_offset+=(ssize_t) title_offset;
665 (void) FormatLocaleString(montage->montage,MaxTextExtent,
666 "%.20gx%.20g%+.20g%+.20g",(double) (extract_info.width+
667 (extract_info.x+border_width)*2),(double) (extract_info.height+
668 (extract_info.y+border_width)*2+(double) ((metrics.ascent-
669 metrics.descent+4)*number_lines+(montage_info->shadow != MagickFalse ? 4 :
670 0))),(double) x_offset,(double) y_offset);
671 *montage->directory='\0';
673 while (tile < MagickMin((ssize_t) tiles_per_page,(ssize_t) number_images))
675 (void) ConcatenateMagickString(montage->directory,
676 image_list[tile]->filename,extent);
677 (void) ConcatenateMagickString(montage->directory,"\n",extent);
680 progress_monitor=SetImageProgressMonitor(montage,(MagickProgressMonitor)
681 NULL,montage->client_data);
682 if (texture != (Image *) NULL)
683 (void) TextureImage(montage,texture,exception);
684 if (montage_info->title != (char *) NULL)
687 geometry[MaxTextExtent];
696 Annotate composite image with title.
698 clone_info=CloneDrawInfo(image_info,draw_info);
699 clone_info->gravity=CenterGravity;
700 clone_info->pointsize*=2.0;
701 (void) GetTypeMetrics(image_list[0],clone_info,&metrics,exception);
702 (void) FormatLocaleString(geometry,MaxTextExtent,
703 "%.20gx%.20g%+.20g%+.20g",(double) montage->columns,(double)
704 (metrics.ascent-metrics.descent),0.0,(double) extract_info.y+4);
705 (void) CloneString(&clone_info->geometry,geometry);
706 (void) CloneString(&clone_info->text,title);
707 (void) AnnotateImage(montage,clone_info,exception);
708 clone_info=DestroyDrawInfo(clone_info);
710 (void) SetImageProgressMonitor(montage,progress_monitor,
711 montage->client_data);
713 Copy tile to the composite.
717 if (montage_info->tile != (char *) NULL)
718 GetMontageGeometry(montage_info->tile,number_images,&x_offset,&y_offset,
720 x_offset+=extract_info.x;
721 y_offset+=(ssize_t) title_offset+extract_info.y;
724 for (tile=0; tile < MagickMin((ssize_t) tiles_per_page,(ssize_t) number_images); tile++)
727 Copy this tile to the composite.
729 image=CloneImage(image_list[tile],0,0,MagickTrue,exception);
730 progress_monitor=SetImageProgressMonitor(image,
731 (MagickProgressMonitor) NULL,image->client_data);
732 width=concatenate != MagickFalse ? image->columns : extract_info.width;
733 if (image->rows > max_height)
734 max_height=image->rows;
735 height=concatenate != MagickFalse ? max_height : extract_info.height;
736 if (border_width != 0)
745 Put a border around the image.
747 border_info.width=border_width;
748 border_info.height=border_width;
749 if (montage_info->frame != (char *) NULL)
751 border_info.width=(width-image->columns+1)/2;
752 border_info.height=(height-image->rows+1)/2;
754 border_image=BorderImage(image,&border_info,image->compose,exception);
755 if (border_image != (Image *) NULL)
757 image=DestroyImage(image);
760 if ((montage_info->frame != (char *) NULL) &&
761 (image->compose == DstOutCompositeOp))
763 SetPixelChannelMapMask(image,AlphaChannel);
764 (void) NegateImage(image,MagickFalse,exception);
765 SetPixelChannelMapMask(image,DefaultChannels);
769 Gravitate as specified by the tile gravity.
771 tile_image->columns=width;
772 tile_image->rows=height;
773 tile_image->gravity=montage_info->gravity;
774 if (image->gravity != UndefinedGravity)
775 tile_image->gravity=image->gravity;
776 (void) FormatLocaleString(tile_geometry,MaxTextExtent,"%.20gx%.20g+0+0",
777 (double) image->columns,(double) image->rows);
778 flags=ParseGravityGeometry(tile_image,tile_geometry,&geometry,exception);
779 x=(ssize_t) (geometry.x+border_width);
780 y=(ssize_t) (geometry.y+border_width);
781 if ((montage_info->frame != (char *) NULL) && (bevel_width != 0))
790 Put an ornamental border around this tile.
792 extract_info=frame_info;
793 extract_info.width=width+2*frame_info.width;
794 extract_info.height=height+2*frame_info.height;
795 value=GetImageProperty(image,"label",exception);
796 if (value != (const char *) NULL)
797 extract_info.height+=(size_t) ((metrics.ascent-
798 metrics.descent+4)*MultilineCensus(value));
799 frame_image=FrameImage(image,&extract_info,image->compose,exception);
800 if (frame_image != (Image *) NULL)
802 image=DestroyImage(image);
808 if (LocaleCompare(image->magick,"NULL") != 0)
811 Composite background with tile.
813 if (montage_info->shadow != MagickFalse)
821 (void) QueryColorCompliance("#00000000",AllCompliance,
822 &image->background_color,exception);
823 shadow_image=ShadowImage(image,80.0,2.0,0.0,5,5,exception);
824 if (shadow_image != (Image *) NULL)
826 (void) CompositeImage(shadow_image,OverCompositeOp,image,0,0,
828 image=DestroyImage(image);
832 (void) CompositeImage(montage,image->compose,image,x_offset+x,
833 y_offset+y,exception);
834 value=GetImageProperty(image,"label",exception);
835 if (value != (const char *) NULL)
838 geometry[MaxTextExtent];
841 Annotate composite tile with label.
843 (void) FormatLocaleString(geometry,MaxTextExtent,
844 "%.20gx%.20g%+.20g%+.20g",(double) ((montage_info->frame ?
845 image->columns : width)-2*border_width),(double)
846 (metrics.ascent-metrics.descent+4)*MultilineCensus(value),
847 (double) (x_offset+border_width),(double)
848 ((montage_info->frame ? y_offset+height+border_width+4 :
849 y_offset+extract_info.height+border_width+
850 (montage_info->shadow != MagickFalse ? 4 : 0))+bevel_width));
851 (void) CloneString(&draw_info->geometry,geometry);
852 (void) CloneString(&draw_info->text,value);
853 (void) AnnotateImage(montage,draw_info,exception);
856 x_offset+=(ssize_t) (width+2*(extract_info.x+border_width));
857 if (((tile+1) == (ssize_t) tiles_per_page) ||
858 (((tile+1) % tiles_per_row) == 0))
860 x_offset=extract_info.x;
861 y_offset+=(ssize_t) (height+(extract_info.y+border_width)*2+
862 (metrics.ascent-metrics.descent+4)*number_lines+
863 (montage_info->shadow != MagickFalse ? 4 : 0));
866 if (images->progress_monitor != (MagickProgressMonitor) NULL)
871 proceed=SetImageProgress(image,MontageImageTag,tiles,total_tiles);
872 if (proceed == MagickFalse)
875 image_list[tile]=DestroyImage(image_list[tile]);
876 image=DestroyImage(image);
880 if ((i+1) < (ssize_t) images_per_page)
883 Allocate next image structure.
885 AcquireNextImage(clone_info,montage,exception);
886 if (GetNextImageInList(montage) == (Image *) NULL)
888 montage=DestroyImageList(montage);
889 return((Image *) NULL);
891 montage=GetNextImageInList(montage);
892 montage->background_color=montage_info->background_color;
893 image_list+=tiles_per_page;
894 number_images-=tiles_per_page;
897 tile_image=DestroyImage(tile_image);
898 if (texture != (Image *) NULL)
899 texture=DestroyImage(texture);
900 master_list=(Image **) RelinquishMagickMemory(master_list);
901 draw_info=DestroyDrawInfo(draw_info);
902 clone_info=DestroyImageInfo(clone_info);
903 return(GetFirstImageInList(montage));