At the icecream sprint, it was suggested that it would be handy to have a method to get the supported mime types for an image toolkit so here is my shot at it.
I have added a function to the gd toolkit to return the supported mime types based on the existence of certain gd functions. Then there is a main image function to use Drupal file_mimetype_mapping to get a list of all possible extensions.
This will also need to be added for Imagemagick. It can return the list of mime types and implement file_mimetype_mapping_alter to add more types, if not all the mime types and extensions that it supports are in the default Drupal types array. I can probably do it, but I don't know where to go about looking up official mime types for all the formats it supports.
Thoughts?
Logan
| Comment | File | Size | Author |
|---|---|---|---|
| image_gd_mime_types.patch | 2.36 KB | loganfsmyth |
Comments
Comment #1
cburschkaOther than a load of code-style quibbles, this looks very good.
One blank line between functions.
The PHPdoc comment needs a period at the end and should line-wrap at 80 characters.
Also, specify the @param and @return values.
I think we generally use !isset() or empty() there. All of these will return the same value when $toolkit is NULL.
The new style guide specifies a space on both sides of the string-concatenating dot.
For a consistent return value, the function should probably be returning an empty array().
If the return value (see above) is made into an array, you only need to check count().
It is also more readable if you use ">" instead of "!=", making it clear that you are expecting a positive value.
See string concatenation; add a space.
Mh... I'm really trying to understand what's going on there, and an inline comment would probably help a lot. I gather the mime type is first searched for in the type mapping, after which the id of the mime type is searched for in the extension mapping?
An empty array() might be a better return value here too.
Space between functions...
See more regarding PHP doc above. This one has no parameters, but the @return value needs to be specified.
This review is powered by Dreditor.
Comment #2
RSpliet commentedDespite the positive feedback it is unfortunate to see that this patch did not make it to mainline. Is there a particular reason for the patch not receiving any updates before inclusion in D7?