Powered by Pair ImageMagick logo
Image Magick
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

ImageMagick-6.1.1/coders/html.c

Go to the documentation of this file.
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % H H TTTTT M M L % 00007 % H H T MM MM L % 00008 % HHHHH T M M M L % 00009 % H H T M M L % 00010 % H H T M M LLLLL % 00011 % % 00012 % % 00013 % Write A Client-Side Image Map Using % 00014 % Image Montage & Directory Information. % 00015 % % 00016 % Software Design % 00017 % John Cristy % 00018 % July 1992 % 00019 % % 00020 % % 00021 % Copyright 1999-2004 ImageMagick Studio LLC, a non-profit organization % 00022 % dedicated to making software imaging solutions freely available. % 00023 % % 00024 % You may not use this file except in compliance with the License. You may % 00025 % obtain a copy of the License at % 00026 % % 00027 % http://www.imagemagick.org/www/Copyright.html % 00028 % % 00029 % Unless required by applicable law or agreed to in writing, software % 00030 % distributed under the License is distributed on an "AS IS" BASIS, % 00031 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 00032 % See the License for the specific language governing permissions and % 00033 % limitations under the License. % 00034 % % 00035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00036 % 00037 % 00038 */ 00039 00040 /* 00041 Include declarations. 00042 */ 00043 #include "magick/studio.h" 00044 #include "magick/attribute.h" 00045 #include "magick/blob.h" 00046 #include "magick/blob_private.h" 00047 #include "magick/color_private.h" 00048 #include "magick/colorspace.h" 00049 #include "magick/constitute.h" 00050 #include "magick/error.h" 00051 #include "magick/error_private.h" 00052 #include "magick/geometry.h" 00053 #include "magick/magick.h" 00054 #include "magick/memory_.h" 00055 #include "magick/paint.h" 00056 #include "magick/static.h" 00057 #include "magick/string_.h" 00058 #include "magick/utility.h" 00059 00060 /* 00061 Forward declarations. 00062 */ 00063 static MagickBooleanType 00064 WriteHTMLImage(const ImageInfo *,Image *); 00065 00066 /* 00067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00068 % % 00069 % % 00070 % % 00071 % I s H T M L % 00072 % % 00073 % % 00074 % % 00075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00076 % 00077 % IsHTML() returns MagickTrue if the image format type, identified by the 00078 % magick string, is HTML. 00079 % 00080 % The format of the IsHTML method is: 00081 % 00082 % MagickBooleanType IsHTML(const unsigned char *magick,const size_t length) 00083 % 00084 % A description of each parameter follows: 00085 % 00086 % o magick: This string is generally the first few bytes of an image file 00087 % or blob. 00088 % 00089 % o length: Specifies the length of the magick string. 00090 % 00091 % 00092 */ 00093 static MagickBooleanType IsHTML(const unsigned char *magick,const size_t length) 00094 { 00095 if (length < 5) 00096 return(MagickFalse); 00097 if (LocaleNCompare((char *) magick,"<html",5) == 0) 00098 return(MagickTrue); 00099 return(MagickFalse); 00100 } 00101 00102 /* 00103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00104 % % 00105 % % 00106 % % 00107 % R e g i s t e r H T M L I m a g e % 00108 % % 00109 % % 00110 % % 00111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00112 % 00113 % RegisterHTMLImage() adds attributes for the HTML image format to 00114 % the list of supported formats. The attributes include the image format 00115 % tag, a method to read and/or write the format, whether the format 00116 % supports the saving of more than one frame to the same file or blob, 00117 % whether the format supports native in-memory I/O, and a brief 00118 % description of the format. 00119 % 00120 % The format of the RegisterHTMLImage method is: 00121 % 00122 % RegisterHTMLImage(void) 00123 % 00124 */ 00125 ModuleExport void RegisterHTMLImage(void) 00126 { 00127 MagickInfo 00128 *entry; 00129 00130 entry=SetMagickInfo("HTM"); 00131 entry->encoder=(EncoderHandler *) WriteHTMLImage; 00132 entry->magick=(MagickHandler *) IsHTML; 00133 entry->adjoin=MagickFalse; 00134 entry->description= 00135 AcquireString("Hypertext Markup Language and a client-side image map"); 00136 entry->module=AcquireString("HTML"); 00137 (void) RegisterMagickInfo(entry); 00138 entry=SetMagickInfo("HTML"); 00139 entry->encoder=(EncoderHandler *) WriteHTMLImage; 00140 entry->magick=(MagickHandler *) IsHTML; 00141 entry->adjoin=MagickFalse; 00142 entry->description= 00143 AcquireString("Hypertext Markup Language and a client-side image map"); 00144 entry->module=AcquireString("HTML"); 00145 (void) RegisterMagickInfo(entry); 00146 entry=SetMagickInfo("SHTML"); 00147 entry->encoder=(EncoderHandler *) WriteHTMLImage; 00148 entry->magick=(MagickHandler *) IsHTML; 00149 entry->adjoin=MagickFalse; 00150 entry->description= 00151 AcquireString("Hypertext Markup Language and a client-side image map"); 00152 entry->module=AcquireString("HTML"); 00153 (void) RegisterMagickInfo(entry); 00154 } 00155 00156 /* 00157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00158 % % 00159 % % 00160 % % 00161 % U n r e g i s t e r H T M L I m a g e % 00162 % % 00163 % % 00164 % % 00165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00166 % 00167 % UnregisterHTMLImage() removes format registrations made by the 00168 % HTML module from the list of supported formats. 00169 % 00170 % The format of the UnregisterHTMLImage method is: 00171 % 00172 % UnregisterHTMLImage(void) 00173 % 00174 */ 00175 ModuleExport void UnregisterHTMLImage(void) 00176 { 00177 (void) UnregisterMagickInfo("HTM"); 00178 (void) UnregisterMagickInfo("HTML"); 00179 (void) UnregisterMagickInfo("SHTML"); 00180 } 00181 00182 /* 00183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00184 % % 00185 % % 00186 % % 00187 % W r i t e H T M L I m a g e % 00188 % % 00189 % % 00190 % % 00191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00192 % 00193 % WriteHTMLImage() writes an image in the HTML encoded image format. 00194 % 00195 % The format of the WriteHTMLImage method is: 00196 % 00197 % MagickBooleanType WriteHTMLImage(const ImageInfo *image_info,Image *image) 00198 % 00199 % A description of each parameter follows. 00200 % 00201 % o image_info: The image info. 00202 % 00203 % o image: The image. 00204 % 00205 % 00206 */ 00207 static MagickBooleanType WriteHTMLImage(const ImageInfo *image_info, 00208 Image *image) 00209 { 00210 char 00211 basename[MaxTextExtent], 00212 buffer[MaxTextExtent], 00213 filename[MaxTextExtent], 00214 mapname[MaxTextExtent], 00215 url[MaxTextExtent]; 00216 00217 Image 00218 *next; 00219 00220 ImageInfo 00221 *write_info; 00222 00223 MagickBooleanType 00224 status; 00225 00226 RectangleInfo 00227 geometry; 00228 00229 register char 00230 *p; 00231 00232 /* 00233 Open image. 00234 */ 00235 assert(image_info != (const ImageInfo *) NULL); 00236 assert(image_info->signature == MagickSignature); 00237 assert(image != (Image *) NULL); 00238 assert(image->signature == MagickSignature); 00239 if (image->debug != MagickFalse) 00240 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image_info->filename); 00241 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); 00242 if (status == MagickFalse) 00243 return(status); 00244 CloseBlob(image); 00245 (void) SetImageColorspace(image,RGBColorspace); 00246 *url='\0'; 00247 if ((LocaleCompare(image_info->magick,"FTP") == 0) || 00248 (LocaleCompare(image_info->magick,"HTTP") == 0)) 00249 { 00250 /* 00251 Extract URL base from filename. 00252 */ 00253 p=strrchr(image->filename,'/'); 00254 if (p) 00255 { 00256 p++; 00257 (void) CopyMagickString(url,image_info->magick,MaxTextExtent); 00258 (void) ConcatenateMagickString(url,":",MaxTextExtent); 00259 url[strlen(url)+p-image->filename]='\0'; 00260 (void) ConcatenateMagickString(url,image->filename, 00261 p-image->filename+2); 00262 (void) CopyMagickString(image->filename,p,MaxTextExtent); 00263 } 00264 } 00265 /* 00266 Refer to image map file. 00267 */ 00268 (void) CopyMagickString(filename,image->filename,MaxTextExtent); 00269 AppendImageFormat("map",filename); 00270 GetPathComponent(filename,BasePath,basename); 00271 (void) CopyMagickString(mapname,basename,MaxTextExtent); 00272 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent); 00273 (void) CopyMagickString(filename,image->filename,MaxTextExtent); 00274 write_info=CloneImageInfo(image_info); 00275 write_info->adjoin=MagickTrue; 00276 status=MagickTrue; 00277 if (LocaleCompare(image_info->magick,"SHTML") != 0) 00278 { 00279 const ImageAttribute 00280 *attribute; 00281 00282 /* 00283 Open output image file. 00284 */ 00285 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); 00286 if (status == MagickFalse) 00287 return(status); 00288 /* 00289 Write the HTML image file. 00290 */ 00291 (void) WriteBlobString(image,"<html version=\"2.0\">\n"); 00292 (void) WriteBlobString(image,"<head>\n"); 00293 attribute=GetImageAttribute(image,"label"); 00294 if (attribute != (const ImageAttribute *) NULL) 00295 (void) FormatMagickString(buffer,MaxTextExtent, 00296 "<title>%s</title>\n",attribute->value); 00297 else 00298 { 00299 GetPathComponent(filename,BasePath,basename); 00300 (void) FormatMagickString(buffer,MaxTextExtent, 00301 "<title>%s</title>\n",basename); 00302 } 00303 (void) WriteBlobString(image,buffer); 00304 (void) WriteBlobString(image,"</head>\n"); 00305 (void) WriteBlobString(image,"<body>\n"); 00306 (void) WriteBlobString(image,"<center>\n"); 00307 (void) FormatMagickString(buffer,MaxTextExtent,"<h1>%s</h1>\n", 00308 image->filename); 00309 (void) WriteBlobString(image,buffer); 00310 (void) WriteBlobString(image,"<br><br>\n"); 00311 (void) CopyMagickString(filename,image->filename,MaxTextExtent); 00312 AppendImageFormat("gif",filename); 00313 (void) FormatMagickString(buffer,MaxTextExtent, 00314 "<img ismap usemap=\"#%s\" src=\"%s\" border=0>\n", 00315 mapname,filename); 00316 (void) WriteBlobString(image,buffer); 00317 /* 00318 Determine the size and location of each image tile. 00319 */ 00320 SetGeometry(image,&geometry); 00321 if (image->montage != (char *) NULL) 00322 (void) ParseAbsoluteGeometry(image->montage,&geometry); 00323 /* 00324 Write an image map. 00325 */ 00326 (void) FormatMagickString(buffer,MaxTextExtent,"<map name=\"%s\">\n", 00327 mapname); 00328 (void) WriteBlobString(image,buffer); 00329 (void) FormatMagickString(buffer,MaxTextExtent," <area href=\"%s", 00330 url); 00331 (void) WriteBlobString(image,buffer); 00332 if (image->directory == (char *) NULL) 00333 { 00334 (void) FormatMagickString(buffer,MaxTextExtent, 00335 "%s\" shape=rect coords=\"0,0,%lu,%lu\">\n",image->filename, 00336 geometry.width-1,geometry.height-1); 00337 (void) WriteBlobString(image,buffer); 00338 } 00339 else 00340 for (p=image->directory; *p != '\0'; p++) 00341 if (*p != '\n') 00342 (void) WriteBlobByte(image,(unsigned char) *p); 00343 else 00344 { 00345 (void) FormatMagickString(buffer,MaxTextExtent, 00346 "\" shape=rect coords=\"%ld,%ld,%ld,%ld\">\n",geometry.x, 00347 geometry.y,geometry.x+(long) geometry.width-1,geometry.y+ 00348 (long) geometry.height-1); 00349 (void) WriteBlobString(image,buffer); 00350 if (*(p+1) != '\0') 00351 { 00352 (void) FormatMagickString(buffer,MaxTextExtent, 00353 " <area href=%s\"",url); 00354 (void) WriteBlobString(image,buffer); 00355 } 00356 geometry.x+=geometry.width; 00357 if (geometry.x >= (long) image->columns) 00358 { 00359 geometry.x=0; 00360 geometry.y+=geometry.height; 00361 } 00362 } 00363 (void) WriteBlobString(image,"</map>\n"); 00364 if (image->montage != (char *) NULL) 00365 { 00366 MagickPixelPacket 00367 fill; 00368 00369 PixelPacket 00370 pixel; 00371 00372 pixel=GetOnePixel(image,0,0); 00373 GetMagickPixelPacket(image,&fill); 00374 SetMagickPixelPacket(&pixel,(IndexPacket *) NULL,&fill); 00375 (void) PaintTransparentImage(image,&fill,TransparentOpacity); 00376 } 00377 (void) CopyMagickString(filename,image->filename,MaxTextExtent); 00378 (void) WriteBlobString(image,"</center>\n"); 00379 (void) WriteBlobString(image,"</body>\n"); 00380 (void) WriteBlobString(image,"</html>\n"); 00381 CloseBlob(image); 00382 /* 00383 Write the image as transparent GIF. 00384 */ 00385 (void) CopyMagickString(image->filename,filename,MaxTextExtent); 00386 AppendImageFormat("gif",image->filename); 00387 next=image->next; 00388 image->next=(Image *) NULL; 00389 (void) strcpy(image->magick,"GIF"); 00390 (void) WriteImage(write_info,image); 00391 image->next=next; 00392 /* 00393 Determine image map filename. 00394 */ 00395 GetPathComponent(image->filename,BasePath,filename); 00396 (void) ConcatenateMagickString(filename,"_map.shtml",MaxTextExtent); 00397 (void) CopyMagickString(image->filename,filename,MaxTextExtent); 00398 } 00399 /* 00400 Open image map. 00401 */ 00402 status=OpenBlob(write_info,image,WriteBinaryBlobMode,&image->exception); 00403 if (status == MagickFalse) 00404 return(status); 00405 write_info=DestroyImageInfo(write_info); 00406 /* 00407 Determine the size and location of each image tile. 00408 */ 00409 SetGeometry(image,&geometry); 00410 if (image->montage != (char *) NULL) 00411 (void) ParseAbsoluteGeometry(image->montage,&geometry); 00412 /* 00413 Write an image map. 00414 */ 00415 (void) FormatMagickString(buffer,MaxTextExtent,"<map name=\"%s\">\n", 00416 mapname); 00417 (void) WriteBlobString(image,buffer); 00418 (void) FormatMagickString(buffer,MaxTextExtent," <area href=\"%s",url); 00419 (void) WriteBlobString(image,buffer); 00420 if (image->directory == (char *) NULL) 00421 { 00422 (void) FormatMagickString(buffer,MaxTextExtent, 00423 "%s\" shape=rect coords=\"0,0,%lu,%lu\">\n",image->filename, 00424 geometry.width-1,geometry.height-1); 00425 (void) WriteBlobString(image,buffer); 00426 } 00427 else 00428 for (p=image->directory; *p != '\0'; p++) 00429 if (*p != '\n') 00430 (void) WriteBlobByte(image,(unsigned char) *p); 00431 else 00432 { 00433 (void) FormatMagickString(buffer,MaxTextExtent, 00434 "\" shape=rect coords=\"%ld,%ld,%ld,%ld\">\n",geometry.x,geometry.y, 00435 geometry.x+(long) geometry.width-1,geometry.y+ 00436 (long) geometry.height-1); 00437 (void) WriteBlobString(image,buffer); 00438 if (*(p+1) != '\0') 00439 { 00440 (void) FormatMagickString(buffer,MaxTextExtent, 00441 " <area href=%s\"",url); 00442 (void) WriteBlobString(image,buffer); 00443 } 00444 geometry.x+=geometry.width; 00445 if (geometry.x >= (long) image->columns) 00446 { 00447 geometry.x=0; 00448 geometry.y+=geometry.height; 00449 } 00450 } 00451 (void) WriteBlobString(image,"</map>\n"); 00452 CloseBlob(image); 00453 (void) CopyMagickString(image->filename,filename,MaxTextExtent); 00454 return(status); 00455 }

Generated on Mon Oct 25 13:40:37 2004 for ImageMagick by doxygen 1.3.7
ImageMagick Copyright © 2004, ImageMagick Studio LLC