2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Write A Client-Side Image Map Using %
14 % Image Montage & Directory Information. %
21 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
22 % dedicated to making software imaging solutions freely available. %
24 % You may not use this file except in compliance with the License. You may %
25 % obtain a copy of the License at %
27 % http://www.imagemagick.org/script/license.php %
29 % Unless required by applicable law or agreed to in writing, software %
30 % distributed under the License is distributed on an "AS IS" BASIS, %
31 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
32 % See the License for the specific language governing permissions and %
33 % limitations under the License. %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/color-private.h"
47 #include "MagickCore/colorspace.h"
48 #include "MagickCore/colorspace-private.h"
49 #include "MagickCore/constitute.h"
50 #include "MagickCore/exception.h"
51 #include "MagickCore/exception-private.h"
52 #include "MagickCore/geometry.h"
53 #include "MagickCore/list.h"
54 #include "MagickCore/magick.h"
55 #include "MagickCore/memory_.h"
56 #include "MagickCore/paint.h"
57 #include "MagickCore/property.h"
58 #include "MagickCore/quantum-private.h"
59 #include "MagickCore/static.h"
60 #include "MagickCore/string_.h"
61 #include "MagickCore/module.h"
62 #include "MagickCore/utility.h"
67 static MagickBooleanType
68 WriteHTMLImage(const ImageInfo *,Image *);
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 % IsHTML() returns MagickTrue if the image format type, identified by the
82 % magick string, is HTML.
84 % The format of the IsHTML method is:
86 % MagickBooleanType IsHTML(const unsigned char *magick,const size_t length)
88 % A description of each parameter follows:
90 % o magick: compare image format pattern against these bytes.
92 % o length: Specifies the length of the magick string.
95 static MagickBooleanType IsHTML(const unsigned char *magick,const size_t length)
99 if (LocaleNCompare((char *) magick,"<html",5) == 0)
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 % R e g i s t e r H T M L I m a g e %
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 % RegisterHTMLImage() adds properties for the HTML image format to
116 % the list of supported formats. The properties include the image format
117 % tag, a method to read and/or write the format, whether the format
118 % supports the saving of more than one frame to the same file or blob,
119 % whether the format supports native in-memory I/O, and a brief
120 % description of the format.
122 % The format of the RegisterHTMLImage method is:
124 % size_t RegisterHTMLImage(void)
127 ModuleExport size_t RegisterHTMLImage(void)
132 entry=SetMagickInfo("HTM");
133 entry->encoder=(EncodeImageHandler *) WriteHTMLImage;
134 entry->magick=(IsImageFormatHandler *) IsHTML;
135 entry->adjoin=MagickFalse;
136 entry->description=ConstantString(
137 "Hypertext Markup Language and a client-side image map");
138 entry->module=ConstantString("HTML");
139 (void) RegisterMagickInfo(entry);
140 entry=SetMagickInfo("HTML");
141 entry->encoder=(EncodeImageHandler *) WriteHTMLImage;
142 entry->magick=(IsImageFormatHandler *) IsHTML;
143 entry->adjoin=MagickFalse;
144 entry->description=ConstantString(
145 "Hypertext Markup Language and a client-side image map");
146 entry->module=ConstantString("HTML");
147 (void) RegisterMagickInfo(entry);
148 entry=SetMagickInfo("SHTML");
149 entry->encoder=(EncodeImageHandler *) WriteHTMLImage;
150 entry->magick=(IsImageFormatHandler *) IsHTML;
151 entry->adjoin=MagickFalse;
152 entry->description=ConstantString(
153 "Hypertext Markup Language and a client-side image map");
154 entry->module=ConstantString("HTML");
155 (void) RegisterMagickInfo(entry);
156 return(MagickImageCoderSignature);
160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 % U n r e g i s t e r H T M L I m a g e %
168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 % UnregisterHTMLImage() removes format registrations made by the
171 % HTML module from the list of supported formats.
173 % The format of the UnregisterHTMLImage method is:
175 % UnregisterHTMLImage(void)
178 ModuleExport void UnregisterHTMLImage(void)
180 (void) UnregisterMagickInfo("HTM");
181 (void) UnregisterMagickInfo("HTML");
182 (void) UnregisterMagickInfo("SHTML");
186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 % W r i t e H T M L I m a g e %
194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 % WriteHTMLImage() writes an image in the HTML encoded image format.
198 % The format of the WriteHTMLImage method is:
200 % MagickBooleanType WriteHTMLImage(const ImageInfo *image_info,Image *image)
202 % A description of each parameter follows.
204 % o image_info: the image info.
206 % o image: The image.
210 static MagickBooleanType WriteHTMLImage(const ImageInfo *image_info,
214 basename[MaxTextExtent],
215 buffer[MaxTextExtent],
216 filename[MaxTextExtent],
217 mapname[MaxTextExtent],
238 assert(image_info != (const ImageInfo *) NULL);
239 assert(image_info->signature == MagickSignature);
240 assert(image != (Image *) NULL);
241 assert(image->signature == MagickSignature);
242 if (image->debug != MagickFalse)
243 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
244 image_info->filename);
245 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
246 if (status == MagickFalse)
248 (void) CloseBlob(image);
249 if (IsRGBColorspace(image->colorspace) == MagickFalse)
250 (void) TransformImageColorspace(image,RGBColorspace);
252 if ((LocaleCompare(image_info->magick,"FTP") == 0) ||
253 (LocaleCompare(image_info->magick,"HTTP") == 0))
256 Extract URL base from filename.
258 p=strrchr(image->filename,'/');
262 (void) CopyMagickString(url,image_info->magick,MaxTextExtent);
263 (void) ConcatenateMagickString(url,":",MaxTextExtent);
264 url[strlen(url)+p-image->filename]='\0';
265 (void) ConcatenateMagickString(url,image->filename,
266 p-image->filename+2);
267 (void) CopyMagickString(image->filename,p,MaxTextExtent);
271 Refer to image map file.
273 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
274 AppendImageFormat("map",filename);
275 GetPathComponent(filename,BasePath,basename);
276 (void) CopyMagickString(mapname,basename,MaxTextExtent);
277 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
278 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
279 write_info=CloneImageInfo(image_info);
280 write_info->adjoin=MagickTrue;
282 if (LocaleCompare(image_info->magick,"SHTML") != 0)
288 Open output image file.
290 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
291 if (status == MagickFalse)
294 Write the HTML image file.
296 (void) WriteBlobString(image,"<?xml version=\"1.0\" "
297 "encoding=\"US-ASCII\"?>\n");
298 (void) WriteBlobString(image,"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML "
300 "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
301 (void) WriteBlobString(image,"<html>\n");
302 (void) WriteBlobString(image,"<head>\n");
303 value=GetImageProperty(image,"label");
304 if (value != (const char *) NULL)
305 (void) FormatLocaleString(buffer,MaxTextExtent,"<title>%s</title>\n",
309 GetPathComponent(filename,BasePath,basename);
310 (void) FormatLocaleString(buffer,MaxTextExtent,
311 "<title>%s</title>\n",basename);
313 (void) WriteBlobString(image,buffer);
314 (void) WriteBlobString(image,"</head>\n");
315 (void) WriteBlobString(image,"<body style=\"text-align: center;\">\n");
316 (void) FormatLocaleString(buffer,MaxTextExtent,"<h1>%s</h1>\n",
318 (void) WriteBlobString(image,buffer);
319 (void) WriteBlobString(image,"<div>\n");
320 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
321 AppendImageFormat("png",filename);
322 (void) FormatLocaleString(buffer,MaxTextExtent,"<img usemap=\"#%s\" "
323 "src=\"%s\" style=\"border: 0;\" alt=\"Image map\" />\n",mapname,
325 (void) WriteBlobString(image,buffer);
327 Determine the size and location of each image tile.
329 SetGeometry(image,&geometry);
330 if (image->montage != (char *) NULL)
331 (void) ParseAbsoluteGeometry(image->montage,&geometry);
335 (void) FormatLocaleString(buffer,MaxTextExtent,
336 "<map id=\"%s\" name=\"%s\">\n",mapname,mapname);
337 (void) WriteBlobString(image,buffer);
338 (void) FormatLocaleString(buffer,MaxTextExtent," <area href=\"%s",
340 (void) WriteBlobString(image,buffer);
341 if (image->directory == (char *) NULL)
343 (void) FormatLocaleString(buffer,MaxTextExtent,
344 "%s\" shape=\"rect\" coords=\"0,0,%.20g,%.20g\" alt=\"\" />\n",
345 image->filename,(double) geometry.width-1,(double) geometry.height-
347 (void) WriteBlobString(image,buffer);
350 for (p=image->directory; *p != '\0'; p++)
352 (void) WriteBlobByte(image,(unsigned char) *p);
355 (void) FormatLocaleString(buffer,MaxTextExtent,"\" shape="
356 "\"rect\" coords=\"%.20g,%.20g,%.20g,%.20g\" alt=\"\" />\n",
357 (double) geometry.x,(double) geometry.y,(double) (geometry.x+
358 geometry.width-1),(double) (geometry.y+geometry.height-1));
359 (void) WriteBlobString(image,buffer);
362 (void) FormatLocaleString(buffer,MaxTextExtent,
363 " <area href=%s\"",url);
364 (void) WriteBlobString(image,buffer);
366 geometry.x+=(ssize_t) geometry.width;
367 if ((geometry.x+4) >= (ssize_t) image->columns)
370 geometry.y+=(ssize_t) geometry.height;
373 (void) WriteBlobString(image,"</map>\n");
374 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
375 (void) WriteBlobString(image,"</div>\n");
376 (void) WriteBlobString(image,"</body>\n");
377 (void) WriteBlobString(image,"</html>\n");
378 (void) CloseBlob(image);
380 Write the image as PNG.
382 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
383 AppendImageFormat("png",image->filename);
384 next=GetNextImageInList(image);
385 image->next=NewImageList();
386 (void) CopyMagickString(image->magick,"PNG",MaxTextExtent);
387 (void) WriteImage(write_info,image);
390 Determine image map filename.
392 GetPathComponent(image->filename,BasePath,filename);
393 (void) ConcatenateMagickString(filename,"_map.shtml",MaxTextExtent);
394 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
399 status=OpenBlob(write_info,image,WriteBinaryBlobMode,&image->exception);
400 if (status == MagickFalse)
402 write_info=DestroyImageInfo(write_info);
404 Determine the size and location of each image tile.
406 SetGeometry(image,&geometry);
407 if (image->montage != (char *) NULL)
408 (void) ParseAbsoluteGeometry(image->montage,&geometry);
412 (void) FormatLocaleString(buffer,MaxTextExtent,
413 "<map id=\"%s\" name=\"%s\">\n",mapname,mapname);
414 (void) WriteBlobString(image,buffer);
415 (void) FormatLocaleString(buffer,MaxTextExtent," <area href=\"%s",url);
416 (void) WriteBlobString(image,buffer);
417 if (image->directory == (char *) NULL)
419 (void) FormatLocaleString(buffer,MaxTextExtent,
420 "%s\" shape=\"rect\" coords=\"0,0,%.20g,%.20g\" alt=\"\" />\n",
421 image->filename,(double) geometry.width-1,(double) geometry.height-1);
422 (void) WriteBlobString(image,buffer);
425 for (p=image->directory; *p != '\0'; p++)
427 (void) WriteBlobByte(image,(unsigned char) *p);
430 (void) FormatLocaleString(buffer,MaxTextExtent,"\" shape=\"rect\""
431 " coords=\"%.20g,%.20g,%.20g,%.20g\" alt=\"\" />\n",
432 (double) geometry.x,(double) geometry.y,geometry.x+(double)
433 geometry.width-1,geometry.y+(double) geometry.height-1);
434 (void) WriteBlobString(image,buffer);
437 (void) FormatLocaleString(buffer,MaxTextExtent,
438 " <area href=%s\"",url);
439 (void) WriteBlobString(image,buffer);
441 geometry.x+=(ssize_t) geometry.width;
442 if ((geometry.x+4) >= (ssize_t) image->columns)
445 geometry.y+=(ssize_t) geometry.height;
448 (void) WriteBlobString(image,"</map>\n");
449 (void) CloseBlob(image);
450 (void) CopyMagickString(image->filename,filename,MaxTextExtent);