This source file includes following definitions.
- IsHTML
- RegisterHTMLImage
- UnregisterHTMLImage
- WriteHTMLImage
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/color-private.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/geometry.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/paint.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
static MagickBooleanType
WriteHTMLImage(const ImageInfo *,Image *);
static MagickBooleanType IsHTML(const unsigned char *magick,const size_t length)
{
if (length < 5)
return(MagickFalse);
if (LocaleNCompare((char *) magick,"<html",5) == 0)
return(MagickTrue);
return(MagickFalse);
}
ModuleExport size_t RegisterHTMLImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("HTM");
entry->encoder=(EncodeImageHandler *) WriteHTMLImage;
entry->magick=(IsImageFormatHandler *) IsHTML;
entry->adjoin=MagickFalse;
entry->description=ConstantString(
"Hypertext Markup Language and a client-side image map");
entry->module=ConstantString("HTML");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("HTML");
entry->encoder=(EncodeImageHandler *) WriteHTMLImage;
entry->magick=(IsImageFormatHandler *) IsHTML;
entry->adjoin=MagickFalse;
entry->description=ConstantString(
"Hypertext Markup Language and a client-side image map");
entry->module=ConstantString("HTML");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("SHTML");
entry->encoder=(EncodeImageHandler *) WriteHTMLImage;
entry->magick=(IsImageFormatHandler *) IsHTML;
entry->adjoin=MagickFalse;
entry->description=ConstantString(
"Hypertext Markup Language and a client-side image map");
entry->module=ConstantString("HTML");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterHTMLImage(void)
{
(void) UnregisterMagickInfo("HTM");
(void) UnregisterMagickInfo("HTML");
(void) UnregisterMagickInfo("SHTML");
}
static MagickBooleanType WriteHTMLImage(const ImageInfo *image_info,
Image *image)
{
char
basename[MaxTextExtent],
buffer[MaxTextExtent],
filename[MaxTextExtent],
mapname[MaxTextExtent],
url[MaxTextExtent];
Image
*next;
ImageInfo
*write_info;
MagickBooleanType
status;
RectangleInfo
geometry;
register char
*p;
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
(void) CloseBlob(image);
(void) TransformImageColorspace(image,sRGBColorspace);
*url='\0';
if ((LocaleCompare(image_info->magick,"FTP") == 0) ||
(LocaleCompare(image_info->magick,"HTTP") == 0))
{
p=strrchr(image->filename,'/');
if (p != (char *) NULL)
{
p++;
(void) CopyMagickString(url,image_info->magick,MaxTextExtent);
(void) ConcatenateMagickString(url,":",MaxTextExtent);
url[strlen(url)+p-image->filename]='\0';
(void) ConcatenateMagickString(url,image->filename,
p-image->filename+2);
(void) CopyMagickString(image->filename,p,MaxTextExtent);
}
}
(void) CopyMagickString(filename,image->filename,MaxTextExtent);
AppendImageFormat("map",filename);
GetPathComponent(filename,BasePath,basename);
(void) CopyMagickString(mapname,basename,MaxTextExtent);
(void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
(void) CopyMagickString(filename,image->filename,MaxTextExtent);
write_info=CloneImageInfo(image_info);
*write_info->magick='\0';
write_info->adjoin=MagickTrue;
status=MagickTrue;
if (LocaleCompare(image_info->magick,"SHTML") != 0)
{
const char
*value;
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
(void) WriteBlobString(image,"<?xml version=\"1.0\" "
"encoding=\"US-ASCII\"?>\n");
(void) WriteBlobString(image,"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML "
"1.0 Strict//EN\" "
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
(void) WriteBlobString(image,"<html>\n");
(void) WriteBlobString(image,"<head>\n");
value=GetImageProperty(image,"label");
if (value != (const char *) NULL)
(void) FormatLocaleString(buffer,MaxTextExtent,"<title>%s</title>\n",
value);
else
{
GetPathComponent(filename,BasePath,basename);
(void) FormatLocaleString(buffer,MaxTextExtent,
"<title>%s</title>\n",basename);
}
(void) WriteBlobString(image,buffer);
(void) WriteBlobString(image,"</head>\n");
(void) WriteBlobString(image,"<body style=\"text-align: center;\">\n");
(void) FormatLocaleString(buffer,MaxTextExtent,"<h1>%s</h1>\n",
image->filename);
(void) WriteBlobString(image,buffer);
(void) WriteBlobString(image,"<div>\n");
(void) CopyMagickString(filename,image->filename,MaxTextExtent);
AppendImageFormat("png",filename);
(void) FormatLocaleString(buffer,MaxTextExtent,"<img usemap=\"#%s\" "
"src=\"%s\" style=\"border: 0;\" alt=\"Image map\" />\n",mapname,
filename);
(void) WriteBlobString(image,buffer);
SetGeometry(image,&geometry);
if (image->montage != (char *) NULL)
(void) ParseAbsoluteGeometry(image->montage,&geometry);
(void) FormatLocaleString(buffer,MaxTextExtent,
"<map id=\"%s\" name=\"%s\">\n",mapname,mapname);
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent," <area href=\"%s",url);
(void) WriteBlobString(image,buffer);
if (image->directory == (char *) NULL)
{
(void) FormatLocaleString(buffer,MaxTextExtent,
"%s\" shape=\"rect\" coords=\"0,0,%.20g,%.20g\" alt=\"\" />\n",
image->filename,(double) geometry.width-1,(double) geometry.height-
1);
(void) WriteBlobString(image,buffer);
}
else
for (p=image->directory; *p != '\0'; p++)
if (*p != '\n')
(void) WriteBlobByte(image,(unsigned char) *p);
else
{
(void) FormatLocaleString(buffer,MaxTextExtent,"\" shape="
"\"rect\" coords=\"%.20g,%.20g,%.20g,%.20g\" alt=\"\" />\n",
(double) geometry.x,(double) geometry.y,(double) (geometry.x+
geometry.width-1),(double) (geometry.y+geometry.height-1));
(void) WriteBlobString(image,buffer);
if (*(p+1) != '\0')
{
(void) FormatLocaleString(buffer,MaxTextExtent,
" <area href=%s\"",url);
(void) WriteBlobString(image,buffer);
}
geometry.x+=(ssize_t) geometry.width;
if ((geometry.x+4) >= (ssize_t) image->columns)
{
geometry.x=0;
geometry.y+=(ssize_t) geometry.height;
}
}
(void) WriteBlobString(image,"</map>\n");
(void) CopyMagickString(filename,image->filename,MaxTextExtent);
(void) WriteBlobString(image,"</div>\n");
(void) WriteBlobString(image,"</body>\n");
(void) WriteBlobString(image,"</html>\n");
(void) CloseBlob(image);
(void) CopyMagickString(image->filename,filename,MaxTextExtent);
AppendImageFormat("png",image->filename);
next=GetNextImageInList(image);
image->next=NewImageList();
(void) CopyMagickString(image->magick,"PNG",MaxTextExtent);
(void) WriteImage(write_info,image);
image->next=next;
GetPathComponent(image->filename,BasePath,filename);
(void) ConcatenateMagickString(filename,"_map.shtml",MaxTextExtent);
(void) CopyMagickString(image->filename,filename,MaxTextExtent);
}
status=OpenBlob(write_info,image,WriteBinaryBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
write_info=DestroyImageInfo(write_info);
SetGeometry(image,&geometry);
if (image->montage != (char *) NULL)
(void) ParseAbsoluteGeometry(image->montage,&geometry);
(void) FormatLocaleString(buffer,MaxTextExtent,
"<map id=\"%s\" name=\"%s\">\n",mapname,mapname);
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent," <area href=\"%s",url);
(void) WriteBlobString(image,buffer);
if (image->directory == (char *) NULL)
{
(void) FormatLocaleString(buffer,MaxTextExtent,
"%s\" shape=\"rect\" coords=\"0,0,%.20g,%.20g\" alt=\"\" />\n",
image->filename,(double) geometry.width-1,(double) geometry.height-1);
(void) WriteBlobString(image,buffer);
}
else
for (p=image->directory; *p != '\0'; p++)
if (*p != '\n')
(void) WriteBlobByte(image,(unsigned char) *p);
else
{
(void) FormatLocaleString(buffer,MaxTextExtent,"\" shape=\"rect\""
" coords=\"%.20g,%.20g,%.20g,%.20g\" alt=\"\" />\n",
(double) geometry.x,(double) geometry.y,geometry.x+(double)
geometry.width-1,geometry.y+(double) geometry.height-1);
(void) WriteBlobString(image,buffer);
if (*(p+1) != '\0')
{
(void) FormatLocaleString(buffer,MaxTextExtent,
" <area href=%s\"",url);
(void) WriteBlobString(image,buffer);
}
geometry.x+=(ssize_t) geometry.width;
if ((geometry.x+4) >= (ssize_t) image->columns)
{
geometry.x=0;
geometry.y+=(ssize_t) geometry.height;
}
}
(void) WriteBlobString(image,"</map>\n");
(void) CloseBlob(image);
(void) CopyMagickString(image->filename,filename,MaxTextExtent);
return(status);
}