Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose file mimetype for printing image properties / attributes #7977

Open
Earnestly opened this issue Feb 19, 2025 · 9 comments
Open

Expose file mimetype for printing image properties / attributes #7977

Earnestly opened this issue Feb 19, 2025 · 9 comments

Comments

@Earnestly
Copy link

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

@dlemstra
Copy link
Member

The mime type information is not optimal and I would prefer to not use this in new places.

@fmw42
Copy link

fmw42 commented Feb 19, 2025

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

@Earnestly
Copy link
Author

Earnestly commented Feb 19, 2025

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.)

@fmw42
Copy link

fmw42 commented Feb 19, 2025

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.

@Earnestly
Copy link
Author

Earnestly commented Feb 19, 2025

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

@fmw42
Copy link

fmw42 commented Feb 19, 2025

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?

@Earnestly
Copy link
Author

Earnestly commented Feb 20, 2025

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.)

@urban-warrior
Copy link
Member

urban-warrior commented Feb 22, 2025

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.

@Rhys-T
Copy link

Rhys-T commented Feb 25, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants