- maybe auto-detect only if the image type is available
(see `image-type-available-p').")
+(defvar image-content-type-suffixes
+ '((image/x-icon "ico"))
+ "Alist of MIME Content-Type headers to file name suffixes.
+This is used as a hint by the ImageMagick library when detecting
+image types. If `create-image' is called with a :content-type
+matching found in this alist, the ImageMagick library will be
+told that the data would have this suffix if saved to a file.")
+
(defcustom image-load-path
(list (file-name-as-directory (expand-file-name "images" data-directory))
'data-directory 'load-path)
static Lisp_Object QCcolor_symbols;
static Lisp_Object QCindex, QCmatrix, QCcolor_adjustment, QCmask, QCgeometry;
static Lisp_Object QCcrop, QCrotation;
+static Lisp_Object QCcontent_type;
/* Other symbols. */
IMAGEMAGICK_WIDTH,
IMAGEMAGICK_MAX_HEIGHT,
IMAGEMAGICK_MAX_WIDTH,
+ IMAGEMAGICK_CONTENT_TYPE,
IMAGEMAGICK_ROTATION,
IMAGEMAGICK_CROP,
IMAGEMAGICK_LAST
{":width", IMAGE_INTEGER_VALUE, 0},
{":max-height", IMAGE_INTEGER_VALUE, 0},
{":max-width", IMAGE_INTEGER_VALUE, 0},
+ {":content-type", IMAGE_SYMBOL_VALUE, 0},
{":rotation", IMAGE_NUMBER_VALUE, 0},
{":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0}
};
description = (char *) MagickRelinquishMemory (description);
}
+/* Possibly give ImageMagick some extra help to determine the image
+ type by supplying a "dummy" filename based on the Content-Type. */
+
+static char*
+imagemagick_filename_hint (Lisp_Object spec)
+{
+ Lisp_Object content_type = image_spec_value (spec, QCcontent_type, NULL);
+ Lisp_Object symbol = intern ("image-content-type-suffixes");
+ Lisp_Object suffix;
+ char *name, *prefix = "/tmp/foo.";
+
+ if (NILP (Fboundp (symbol)))
+ return NULL;
+
+ suffix = Fcar (Fcdr (Fassq (content_type, Fsymbol_value (symbol))));
+ if (! STRINGP (suffix))
+ return NULL;
+
+ name = xmalloc (strlen (prefix) + SBYTES (suffix) + 1);
+ strcpy(name, prefix);
+ strcat(name, SDATA (suffix));
+ return name;
+}
+
/* Helper function for imagemagick_load, which does the actual loading
given contents and size, apart from frame and image structures,
passed from imagemagick_load. Uses librimagemagick to do most of
int desired_width, desired_height;
double rotation;
int pixelwidth;
+ char *filename_hint = NULL;
/* Handle image index for image types who can contain more than one image.
Interface :index is same as for GIF. First we "ping" the image to see how
ping_wand = NewMagickWand ();
/* MagickSetResolution (ping_wand, 2, 2); (Bug#10112) */
+ if (! filename)
+ filename_hint = imagemagick_filename_hint (img->spec);
+
+ if (filename_hint)
+ MagickSetFilename (ping_wand, filename_hint);
+
status = filename
? MagickPingImage (ping_wand, filename)
: MagickPingImageBlob (ping_wand, contents, size);
image_wand = NewMagickWand ();
+ if (filename_hint)
+ MagickSetFilename (image_wand, filename_hint);
+
if ((filename
? MagickReadImage (image_wand, filename)
: MagickReadImageBlob (image_wand, contents, size))
/* `MagickWandTerminus' terminates the imagemagick environment. */
MagickWandTerminus ();
+ if (filename_hint)
+ free (filename_hint);
+
return 1;
imagemagick_error:
DestroyMagickWand (image_wand);
if (bg_wand) DestroyPixelWand (bg_wand);
+ if (filename_hint)
+ free (filename_hint);
MagickWandTerminus ();
/* TODO more cleanup. */
DEFSYM (Qpostscript, "postscript");
DEFSYM (QCmax_width, ":max-width");
DEFSYM (QCmax_height, ":max-height");
+ DEFSYM (QCcontent_type, ":content-type");
#ifdef HAVE_GHOSTSCRIPT
ADD_IMAGE_TYPE (Qpostscript);
DEFSYM (QCloader, ":loader");