Expose file mimetype for printing image properties / attributes
Is your feature request related to a problem? Please describe.
I would like to print the mime type of a given file as understood by imagemagick. Currently imagemagick does display the Mime type: when using identify -verbose but there does not appear to be an equivalent attribute.
Describe the solution you'd like
Provide a %[mimetype] attribute so that it may be used with -format or -print
Describe alternatives you've considered
# Fine Free File Command
mime=$(file -b --mime-type -- "$file")
Additional context
No response
The mime type information is not optimal and I would prefer to not use this in new places.
If I understand your request, can't you just use %m or %[fx:m]?
magick lena.png -format "%m" info:
PNG
See https://imagemagick.org/script/escape.php
Not to be flippant, but because %m isn't a mimetype: https://datatracker.ietf.org/doc/html/rfc2045
I had considered %m before but it would need a lookup table to transform imagemagick's file types into mimetypes. E.g.:
{
'PNG' => 'image/png'
'PDF' => 'application/pdf'
'PBF' => 'font/x-postscript-pfb'
'TTF' => 'font/ttf'
'PS' => 'application/postscript'
...
}
I'm unfamiliar (unaware) with the issues @dlemstra has raised about imagemagick's determination of the mimetype string, which I was hoping could "just" be exposed.
(As an aside, being able to use \0 (NUL termination) in -format would be nice. When I last looked into adding this myself the implementation relied on C-strings and so might need a rework to support strings containing NUL bytes.)
Not all your %m are image types. So I do not see how IM would show those in a command for a given image.
Nevertheless, I see what you want and have no idea how you would get what you want, especially for non-image mime types.
Sorry for my misunderstanding of what you wanted.
Indeed, as magick supports more than just image types, e.g. TrueType fonts and PDF documents, I can't just assume all mimetypes would be image/*.
Edit: See magick -list mime
But for the non-image mime types, what command would request that. For example how would you ask for font type if used in an image? Once the image is created, that information is lost. Are you asking to extract that in the command that creates the text image or after the image has been created?
I wouldn't ask imagemagick to return anything more than what it already understands, i.e. from magick -list mime.
The primary purpose is to query mimetype of a file with magick -ping ... -format '%[mimetype]\n' info:
I would be very happy for it to return nothing or an error for those formats it does not understand. (This is particularly important as it helps me maintain a degree of symmetry with the capabilities of imagemagick more generally.)
We'll add a patch to support the "mimetype" property. Look for it in the main branch by the end of day. Use mime:type.
Is it intentional that this mime:type property gets added to PNG files as a tEXt chunk when magick mogrifying them, and is there any way to prevent that?
Edit: Seems to have been fixed in 7.1.1-45, probably by https://github.com/ImageMagick/ImageMagick/commit/14511d8b3643ff76ac8d08a54a12d9f55f867814.